Your code defines the object oBoM at the form level (and being Public, can
be accessed by other VBA code, through the form object 'as if' it was some
new form property). If it is not required, leave it Private.
Your code created an objet oBoM in the form Open event, but does not seems
to initialize it. So, your object oBoM will have all its data set to default
values, unless your oBoM class Initialize event (in the code of
clsBillofmaterial class) does something to its internal data.
Add a break point at the line where your error occur, so just before the
error occurs. Then, once the code stops at the break point (and before
executing the line producing the error)
Check if Me.cbWOID has a not null value.
? Me.cbWOID IS NULL
if it is null, the method NextBoMSeq must have its first argument AS
VARIANT or AS OBJECT (preferably As Variant).
BUT your filter will be in error anyhow, since the concatenated strings
result will be something like:
"BoMWOID= AND BoMSeq=0"
which is not a valid filter (because ... BoMWOID is equal to ... what? )
Check if oBoM is NOT Nothing,
? oBoM IS Nothing
if it is nothing, you have to track where your code set it to nothing (since
the variable is public, that maybe from code living OUTSIDE your form; if
the object is private, only the code in your form, and in class
clsBillofMaterial, can set it to Nothing)
In the Locals window (View | Locals Window), check if your variable oBoM has
all the required properties/methods (and see if the values you can reach
make 'sense', if applicable).
In the immediate debug window, check if oBoM.NextBoMSeq(Me.cbWOID) returns
NOT a NULL value.
? oBoM.NextBoMSeq(Me.cbWOID) IS NULL
If it returns a NULL value, CSTR(Null) will err.
Also check it returns an integer.
? oBoM.NextBoMSeq(Me.cbWOID)
If it returns a string, then the filter become, after concatenation:
"BoMWOID= 44 AND BoMSeq = 0AAA"
as example, and the string has wrong delimiters, it should be:
"BoMWOID= 44 AND BoMSeq = '0AAA' "
or
"BoMWOID= 'B44' AND BoMSeq = '0AAA' "
as example (or something similar). Note that Me.cbWOID should return a
number, else your code need ALSO the proper delimiters for the value
filtering BoMWOID.
In the Immediate Debug Window, check if the concatenated strings result in
something valid for the filter:
? "BoMWOID=" & Me.cbWOID & " AND BoMSeq=0" &
CStr(oBoM.NextBoMSeq(Me.cbWOID))
Note that you can add a line in the Form_Open sub:
Private Sub Form_Open(Cancel As Integer)
Set oBoM = New clsBillofMaterial
Debug.Assert Not oBoM Is Nothing ' assume oBoM is not nothing
End Sub
since, after all, you Assert (assume) the object is not nothing, anymore, at
this point. You can also insert the same line of code as the first line of
code in btnAddNewBoM_Click( ), for the same reason.
And it can be that the problem is something else...
Vanderghast, Access MVP
JimS said:
Well, I'm still having issues...
I decompiled and recompiled, etc. per advice from another poster.
I get an error on the Me. filter= statement in btnAddNewNoM_Click()
routine.
The error refers to oBoM as if it were uninstantiated. I trap it and
try to see a property of the class in the immediate window, and sure
enough,
it's not there.
I have to believe this is some syntax issue.
' Start Code
Option Compare Database
Option Explicit
Dim HourlyRate As Currency
Dim NewBoMHeaderID As Long
Public oBoM As clsBillofMaterial
Private Sub btnAddEmpty_Click()
NewBoMHeaderID = oBoM.AddBoMHeader(Me.cbWOID)
Me.Filter = "tblBoM.BomID=" & NewBoMHeaderID
Me.FilterOn = True
Me.cbWOID.Requery
Me.cbWOID = ""
Me.tbWODesc = ""
End Sub
Private Sub btnAddNewBoM_Click()
Me.Filter = "BoMWOID=" & Me.cbWOID & " AND BoMSeq=0" &
CStr(oBoM.NextBoMSeq(Me.cbWOID))
DoCmd.OpenForm FormName:="popupCloneBoM", Openargs:=CStr(Me.cbWOID)
Me.FilterOn = True
End Sub
Private Sub btnDelete_Click()
oBoM.delete Me.BoMWOID, Me.BoMSeq
End Sub
Private Sub cbWOID_AfterUpdate()
Me.tbWODesc = Me.cbWOID.Column(2)
Me.tbWODesc.Requery
tbHourlyRate.Requery
Me.Filter = "BoMWOID=" & Me.cbWOID & " AND BoMSeq=0" &
Me.cbWOID.Column(3)
Me.FilterOn = True
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Check here to make sure the new quantity is not less than the "picked"
quantity
End Sub
Private Sub Form_Close()
Set oBoM = Nothing
End Sub
Private Sub Form_Load()
HourlyRate = 0
Me.cbWOID = Me.cbWOID.ItemData(0)
Me.Filter = "BoMWOID=" & Me.cbWOID & " AND BoMSeq=0" &
Me.cbWOID.Column(3)
Me.FilterOn = True
Me.tbWODesc = Me.cbWOID.Column(2)
End Sub
Private Sub Form_Open(Cancel As Integer)
Set oBoM = New clsBillofMaterial
End Sub