Thanks for looking at my post.
I have a form, “frmJobCloseOutEntry” that is used to follow an 8 step file close out procedure. On small jobs all 8 steps can usually be completed in one sitting but on larger jobs the user may only be able to complete part of the steps and then come back to this file at another time. Two to three users are involved in this process.
A user upon opening the form begins by entering a file number in a combo box (cboFileNumber) with the record source set to “qryJobCloseOutEntry” [FileNumber] to see it the file close out has already been started. If the file does not already exist it then needs to be entered as a new record. So I thought I’d try to use the NotInList event to handle that. I haven’t had any experience in using the NotInList event but found an example in Martin Green’s web site The code works well in that it adds the new file to the table. But once it’s been added I would like it to become the active record in the form so the user can start working on the close out procedure for that file. How can I do this? Or should I be using a different event. Following is the code I have in the AfterUpdate and NotInList events of cboFileNumber.
Any help will be much apprecidated!
I have a form, “frmJobCloseOutEntry” that is used to follow an 8 step file close out procedure. On small jobs all 8 steps can usually be completed in one sitting but on larger jobs the user may only be able to complete part of the steps and then come back to this file at another time. Two to three users are involved in this process.
A user upon opening the form begins by entering a file number in a combo box (cboFileNumber) with the record source set to “qryJobCloseOutEntry” [FileNumber] to see it the file close out has already been started. If the file does not already exist it then needs to be entered as a new record. So I thought I’d try to use the NotInList event to handle that. I haven’t had any experience in using the NotInList event but found an example in Martin Green’s web site The code works well in that it adds the new file to the table. But once it’s been added I would like it to become the active record in the form so the user can start working on the close out procedure for that file. How can I do this? Or should I be using a different event. Following is the code I have in the AfterUpdate and NotInList events of cboFileNumber.
Any help will be much apprecidated!
Code:
Private Sub cboFileNumber_AfterUpdate()
On Error GoTo cboFileNumber_AfterUpdate_Err
Dim Rs As Object
Set Rs = Me.Recordset.Clone
Rs.FindFirst "[FileNumber] = " & Str(Nz(Me![cboFileNumber], 0))
If Not Rs.EOF Then Me.Bookmark = Rs.Bookmark
cboFileNumber_AfterUpdate_Exit:
Exit Sub
cboFileNumber_AfterUpdate_Err:
MsgBox Err.Description, vbCritical, "Error"
End Sub
Private Sub cboFileNumber_NotInList(NewData As String, Response As Integer)
On Error GoTo cboFileNumber_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The File Number " & Chr(34) & NewData & _
Chr(34) & " you entered is new." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "JCA Job Close-Out")
If intAnswer = vbYes Then
strSQL = "INSERT INTO qryJobCloseOutEntry([FileNumber]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new File Number has been added." _
, vbInformation, "JCA Job Close-out"
Response = acDataErrAdded
Else
MsgBox "Please choose a File Number from the list." _
, vbInformation, "JCA Job Close-out"
Response = acDataErrContinue
End If
cboFileNumber_NotInList_Exit:
Exit Sub
cboFileNumber_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume cboFileNumber_NotInList_Exit
End Sub