C
Chris
Amateur needs help!
I have a main client form with combo box that selects client.
When client doesn't exist the NotInList code opens an entry form.
When the entry form is complete the user uses a command button to close and
return to that record on the main client form.
Everything is as I want, except the message querying whether to add the
NotInList client appears twice: when its not in the list and again at closing
the entry form.
[txtAdding] is a 1 or 0 and is status for use elsewhere.
I cannot see where the problem. Help!
****** code for main client form NotInList ********
Private Sub cboClient_NotInList(NewData As String, Response As Integer)
Dim Result
Dim msg, CR As String
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Ask the user if he or she wishes to add the new customer.
NewData = UCase(NewData)
msg = "'" & NewData & "' is not in the list." & CR & CR
msg = msg & "Do you want to add it?"
If Me.txtAdding = 0 Then
If MsgBox(msg, vbQuestion + vbYesNo) = vbYes Then
' If the user chose Yes, start the Client form in data entry
Me.txtAdding = 1
DoCmd.OpenForm "frm1 ClientEntry", , , , acAdd, acDialog,
NewData
Else
Exit Sub
End If
End If
' Look for the client the user created in the Client form.
Result = DLookup("[ClientID]", "[tbl 1 Client]", "[ClientID]='" & NewData &
"'")
If IsNull(Result) Then
' If the customer was not created, set the Response argument to suppress
an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again!"
Else
' If the customer was created, set the Response argument to indicate that
new data is being added.
Response = acDataErrAdded
End If
Me.txtAdding = 0
End Sub
****** code for client entry form closing command button********
Private Sub btnCloseForm_Click()
On Error GoTo Err_btnCloseForm_Click
Dim NewData As String
Dim frm As Form
Set frm = Forms![frm1 client]
NewData = Me.ClientID
If Me.Dirty Then Me.Dirty = False 'closes
entry form and finds new client
Forms![frm1 client].Form!txtAdding = 0
With frm.RecordsetClone
.FindFirst "ClientID=""" & Me.txtClientID & """"
If Not .NoMatch Then frm.Bookmark = .Bookmark
End With
frm.Requery
Set frm = Nothing
DoCmd.GoToRecord acDataForm, "frm1 Client", acNewRec
DoCmd.Close acForm, "frm1 ClientEntry"
Exit_btnCloseForm_Click:
Exit Sub
Err_btnCloseForm_Click:
MsgBox Err.Description
Resume Exit_btnCloseForm_Click
End Sub
I have a main client form with combo box that selects client.
When client doesn't exist the NotInList code opens an entry form.
When the entry form is complete the user uses a command button to close and
return to that record on the main client form.
Everything is as I want, except the message querying whether to add the
NotInList client appears twice: when its not in the list and again at closing
the entry form.
[txtAdding] is a 1 or 0 and is status for use elsewhere.
I cannot see where the problem. Help!
****** code for main client form NotInList ********
Private Sub cboClient_NotInList(NewData As String, Response As Integer)
Dim Result
Dim msg, CR As String
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Ask the user if he or she wishes to add the new customer.
NewData = UCase(NewData)
msg = "'" & NewData & "' is not in the list." & CR & CR
msg = msg & "Do you want to add it?"
If Me.txtAdding = 0 Then
If MsgBox(msg, vbQuestion + vbYesNo) = vbYes Then
' If the user chose Yes, start the Client form in data entry
Me.txtAdding = 1
DoCmd.OpenForm "frm1 ClientEntry", , , , acAdd, acDialog,
NewData
Else
Exit Sub
End If
End If
' Look for the client the user created in the Client form.
Result = DLookup("[ClientID]", "[tbl 1 Client]", "[ClientID]='" & NewData &
"'")
If IsNull(Result) Then
' If the customer was not created, set the Response argument to suppress
an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again!"
Else
' If the customer was created, set the Response argument to indicate that
new data is being added.
Response = acDataErrAdded
End If
Me.txtAdding = 0
End Sub
****** code for client entry form closing command button********
Private Sub btnCloseForm_Click()
On Error GoTo Err_btnCloseForm_Click
Dim NewData As String
Dim frm As Form
Set frm = Forms![frm1 client]
NewData = Me.ClientID
If Me.Dirty Then Me.Dirty = False 'closes
entry form and finds new client
Forms![frm1 client].Form!txtAdding = 0
With frm.RecordsetClone
.FindFirst "ClientID=""" & Me.txtClientID & """"
If Not .NoMatch Then frm.Bookmark = .Bookmark
End With
frm.Requery
Set frm = Nothing
DoCmd.GoToRecord acDataForm, "frm1 Client", acNewRec
DoCmd.Close acForm, "frm1 ClientEntry"
Exit_btnCloseForm_Click:
Exit Sub
Err_btnCloseForm_Click:
MsgBox Err.Description
Resume Exit_btnCloseForm_Click
End Sub