I have a combo on a form that has contains serial numbers. If the user selects the appropriate serial number a form opens for the record to be edited. If the serial number does not exist the user adds it to the combo and a form opens so the user can add the rest of the information. Opening the same form how can I pass "sn" to the form if the record has to be edited or "newdata" if the record has to be added?
'The code that is run after the selected record is chosen from the combo Private Sub cmbDSerialNumber_AfterUpdate() Me.RecordsetClone.FindFirst "[DSerialNumber] = '" & Me!cmbDSerialNumber & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark End Sub
Private Sub EditDocketBtn_Click()
Dim sn As String
sn = Me.cmbDSerialNumber
DoCmd.OpenForm "DocketsFrm", acNormal, , , acFormEdit, acDialog, sn End Sub
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Dim sn As String
sn = Me.OpenArgs
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "DSerialNumber = '" & sn & "'"
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
End If
End If
Me.Caption = "Serial Number: " & Me!DSerialNumber End Sub
This is my NotInList Procedure. How do I pass NewData in OpenArgs as well?
Private Sub CMBDSerialNumber_NotInList(NewData As String, Response As Integer) Dim Result Dim Msg As String Dim CR As String
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
Msg = "'" & NewData & "' is not in the list." & CR & CR Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then DoCmd.OpenForm "DocketsFrm", , , , acAdd, acDialog, NewData End If
Result = DLookup("[DSerialNumber]", "Dockets", _ "[DSerialNumber]='" & NewData & "'") If IsNull(Result) Then Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End Sub
'The code that is run after the selected record is chosen from the combo Private Sub cmbDSerialNumber_AfterUpdate() Me.RecordsetClone.FindFirst "[DSerialNumber] = '" & Me!cmbDSerialNumber & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark End Sub
Private Sub EditDocketBtn_Click()
Dim sn As String
sn = Me.cmbDSerialNumber
DoCmd.OpenForm "DocketsFrm", acNormal, , , acFormEdit, acDialog, sn End Sub
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Dim sn As String
sn = Me.OpenArgs
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "DSerialNumber = '" & sn & "'"
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
End If
End If
Me.Caption = "Serial Number: " & Me!DSerialNumber End Sub
This is my NotInList Procedure. How do I pass NewData in OpenArgs as well?
Private Sub CMBDSerialNumber_NotInList(NewData As String, Response As Integer) Dim Result Dim Msg As String Dim CR As String
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
Msg = "'" & NewData & "' is not in the list." & CR & CR Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then DoCmd.OpenForm "DocketsFrm", , , , acAdd, acDialog, NewData End If
Result = DLookup("[DSerialNumber]", "Dockets", _ "[DSerialNumber]='" & NewData & "'") If IsNull(Result) Then Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End Sub