Since I cannot write code myself, I copied the following code from an old post and got it working in my database, but I would like it to copy the name already entered in the cboTo combo box so that the user doesn't have to retype it in the frmFaxListAddContact entry form.
Private Sub cboTo_NotInList(NewData As String, Response As Integer)
On Error GoTo cboTo_NotInList_Err
'Add a new record to the FaxList table
'and requery the cboTo combo box
Dim NewContact As Integer, MsgTitle As String, MsgDialog As Integer
Const MB_YESNO = 4
Const MB_ICONEXCLAMATION = 48
Const MB_DEFBUTTON1 = 0, IDYES = 6, IDNO = 7
'Make sure the user really wants to add it
MsgTitle = "Contact is not in the list"
MsgDialog = MB_YESNO + MB_ICONEXCLAMATION + MB_DEFBUTTON1
NewContact = MsgBox("Do you want to add the new Contact?", MsgDialog, MsgTitle)
If NewContact = IDNO Then
Response = DATA_ERRCONTINUE
' Display a customized message.
MsgBox "You have chosen NOT to enter a new Contact. Please choose a name from the list."
Else
DoCmd.OpenForm "frmFaxListAddContact", acNormal, , , acAdd, acDialog
Response = DATA_ERRADDED
End If
cboTo_Exit:
Exit Sub
cboTo_NotInList_Err:
MsgBox Err.Description
Resume cboTo_Exit
End Sub
I tried adding this line:
Forms!frmFaxListAddContact.txtContact = Forms!frmSelect1.cboTo.Text
after the DoCmd.Openform, but since the frmFaxListAddContact form was opened acDialog, the code did not execute. When I removed the ", acDialog", the name was set in the frmFaxListAddContact form, but then the rest of the code immediately executed and I got the generic Not in List error message without getting the chance to complete the new entry.
Would the thing to do be to pause the code until the frmFaxListAddContact form is closed, and if so, how do I do this?
Private Sub cboTo_NotInList(NewData As String, Response As Integer)
On Error GoTo cboTo_NotInList_Err
'Add a new record to the FaxList table
'and requery the cboTo combo box
Dim NewContact As Integer, MsgTitle As String, MsgDialog As Integer
Const MB_YESNO = 4
Const MB_ICONEXCLAMATION = 48
Const MB_DEFBUTTON1 = 0, IDYES = 6, IDNO = 7
'Make sure the user really wants to add it
MsgTitle = "Contact is not in the list"
MsgDialog = MB_YESNO + MB_ICONEXCLAMATION + MB_DEFBUTTON1
NewContact = MsgBox("Do you want to add the new Contact?", MsgDialog, MsgTitle)
If NewContact = IDNO Then
Response = DATA_ERRCONTINUE
' Display a customized message.
MsgBox "You have chosen NOT to enter a new Contact. Please choose a name from the list."
Else
DoCmd.OpenForm "frmFaxListAddContact", acNormal, , , acAdd, acDialog
Response = DATA_ERRADDED
End If
cboTo_Exit:
Exit Sub
cboTo_NotInList_Err:
MsgBox Err.Description
Resume cboTo_Exit
End Sub
I tried adding this line:
Forms!frmFaxListAddContact.txtContact = Forms!frmSelect1.cboTo.Text
after the DoCmd.Openform, but since the frmFaxListAddContact form was opened acDialog, the code did not execute. When I removed the ", acDialog", the name was set in the frmFaxListAddContact form, but then the rest of the code immediately executed and I got the generic Not in List error message without getting the chance to complete the new entry.
Would the thing to do be to pause the code until the frmFaxListAddContact form is closed, and if so, how do I do this?