S
Seren
I have a subform that I am trying to get to look up a tool number. the user
enters a tool number, then if it already exists, they are redirected to the
existing record. If not, they can continue to fill out the info and create a
new record. at the first keystroke, I get an error that says "You tried to
assign a NULL value to a variable that is not a variant data type." Now, I
know dealing with the error is one thing... and if anyone has suggestions on
that, I'd be more than happy to take them. But the question *for now* is why
is it doing this on the first keystroke? I want to be able to type in a
whole tool number, then when the user tabs off or clicks somewhere else, if
the record already exists in the tool table, it redirects them to the record.
The following code is what I'm trying to use to look up the tool number in
the subform, and is located in the code-behind page for the subform. SHould
it be in the subform control Sub in the Form3 (main form) page? (Subform
name = subTool2; subform *control* name = subTool)
Private Sub ToolNum_AfterUpdate()
Dim TNum As Variant
Dim stDup As String
Dim ToolID As Integer
Dim rsc As DAO.Recordset
Set rsc = Form_Form3.subTool.Form.RecordsetClone
'Set TNum = Form_Form3.subTool.Form.ToolNum.Value
TNum = Form_subTool2.txtToolNum.Value
stDup = "ToolNum = " & "'" & TNum & "'"
' check if toolnum already exists in tblTool
'If DCount("ToolNum", "tblTool", stDup) > 0 Then
If Trim(txtToolNum.Text) = "" Then
MsgBox ("You must enter a tool number")
txtToolNum.SetFocus
ElseIf DCount("ToolNum", "tblTool", stDup) > 0 Then
MsgBox ("corresponding tool number was found")
' clear toolNum field
Form_Form3.subTool.Form.Undo
' set form to existing matching record
ToolID = Nz(DLookup("[TOOLID]", "tblTool", "txtToolNum ='" & TNum &
"'"))
Form_Form3.ToolID = ToolID
Form_Form3.subTool.Form.RecordSource = "Select * from tblTool where
ToolNum = '" & TNum & "'"
Form_Form3.subTool.Form.Requery
'rsc.FindFirst stDup
' DoCmd.FindRecord TNum
' DoCmd.GoToRecord acTable, "subTool", acGoTo, TNum
'Form_Form2.subTool.Form.Bookmark = rsc.Bookmark
' MsgBox ("you were taken to the corresponding tool number- Tool
Number: " & ToolNum & _
", Boards Per Panel: " & BdsPerPanel)
End If
If IsNull(ToolNum) Then
MsgBox ("You must enter a tool number to save this record.")
txtToolNum.SetFocus
End If
'Set rsc = Nothing
DoCmd.Save
End Sub
Thanks!!
Seren
enters a tool number, then if it already exists, they are redirected to the
existing record. If not, they can continue to fill out the info and create a
new record. at the first keystroke, I get an error that says "You tried to
assign a NULL value to a variable that is not a variant data type." Now, I
know dealing with the error is one thing... and if anyone has suggestions on
that, I'd be more than happy to take them. But the question *for now* is why
is it doing this on the first keystroke? I want to be able to type in a
whole tool number, then when the user tabs off or clicks somewhere else, if
the record already exists in the tool table, it redirects them to the record.
The following code is what I'm trying to use to look up the tool number in
the subform, and is located in the code-behind page for the subform. SHould
it be in the subform control Sub in the Form3 (main form) page? (Subform
name = subTool2; subform *control* name = subTool)
Private Sub ToolNum_AfterUpdate()
Dim TNum As Variant
Dim stDup As String
Dim ToolID As Integer
Dim rsc As DAO.Recordset
Set rsc = Form_Form3.subTool.Form.RecordsetClone
'Set TNum = Form_Form3.subTool.Form.ToolNum.Value
TNum = Form_subTool2.txtToolNum.Value
stDup = "ToolNum = " & "'" & TNum & "'"
' check if toolnum already exists in tblTool
'If DCount("ToolNum", "tblTool", stDup) > 0 Then
If Trim(txtToolNum.Text) = "" Then
MsgBox ("You must enter a tool number")
txtToolNum.SetFocus
ElseIf DCount("ToolNum", "tblTool", stDup) > 0 Then
MsgBox ("corresponding tool number was found")
' clear toolNum field
Form_Form3.subTool.Form.Undo
' set form to existing matching record
ToolID = Nz(DLookup("[TOOLID]", "tblTool", "txtToolNum ='" & TNum &
"'"))
Form_Form3.ToolID = ToolID
Form_Form3.subTool.Form.RecordSource = "Select * from tblTool where
ToolNum = '" & TNum & "'"
Form_Form3.subTool.Form.Requery
'rsc.FindFirst stDup
' DoCmd.FindRecord TNum
' DoCmd.GoToRecord acTable, "subTool", acGoTo, TNum
'Form_Form2.subTool.Form.Bookmark = rsc.Bookmark
' MsgBox ("you were taken to the corresponding tool number- Tool
Number: " & ToolNum & _
", Boards Per Panel: " & BdsPerPanel)
End If
If IsNull(ToolNum) Then
MsgBox ("You must enter a tool number to save this record.")
txtToolNum.SetFocus
End If
'Set rsc = Nothing
DoCmd.Save
End Sub
Thanks!!
Seren