themurph2000
Fat, drunk, and stupid
- Local time
- Yesterday, 19:04
- Joined
- Sep 24, 2007
- Messages
- 181
Hello. I was trying to diagnose why a form I created, which will search for a record in a table based on criteria in the form, then ask to create it if it doesn't exist, crashes whenever someone answers "no" to the question. Here's the code I cobbled together (or configured for my use, as it were)
Since the code has no problem when "yes" is clicked, I figured I must be putting something in there that shouldn't be or forgot to put something in.
Thank you for any suggestions.
Code:
Private Sub Command16_Click()
Dim rt As Object
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("RateList", dbOpenDynaset, dbAppendOnly)
If DCount("*", "RateList", "JCN = " & Forms!frm_searchjcnlist!txt_invisible_jcnnumber) = 0 Then
If MsgBox("The Record is Not in the Rate List. Would you like to add it?", vbYesNo) = vbYes Then
rs.AddNew
rs!JCN = Me.txt_invisible_jcnnumber
rs!ParentItem = Me.txt_invisible_jcnparent
rs!OriginalName = Me.txt_invisible_jcnparent
rs!CreatedDate = Date
rs.Update
Me.Requery
Else: Me.txt_invisible_jcnparent = ""
Me.txt_invisible_jcnnumber = ""
End If
End If
' Find the record that matches the control.
Set rt = Forms!frm_searchjcnlist.Recordset.Clone
rt.FindFirst "[JCN] = " & Str(Nz(Me![txt_invisible_jcnnumber], 0))
If Not rt.EOF Then Forms!frm_searchjcnlist.Bookmark = rt.Bookmark
Me.txt_invisible_jcnparent = ""
Me.txt_invisible_jcnnumber = ""
End Sub
Since the code has no problem when "yes" is clicked, I figured I must be putting something in there that shouldn't be or forgot to put something in.
Thank you for any suggestions.