Hi, Keith.
How can I set a msg box up for the user, if the text is not on the list. At
this time it gives a defauld msg.
The custom message may created in the combo box's OnNotInList( ) event. A
common method is to give the user the custom message that the item is not one
of the approved items to select and then allow the user to add it to the
table. In the following example, cboContact is the name of the combo box:
Private Sub cboContact_NotInList(NewData As String, Response As Integer)
On Error GoTo ErrHandler
MsgBox "Please double-click this field" & vbCrLf & _
"to add a new entry to the list.", _
vbInformation + vbOKOnly, "No Matching Record"
Response = acDataErrContinue
Exit Sub
ErrHandler:
MsgBox "Error in cboContact_NotInList( ) in " & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
In the combo box's OnDblClick( ) event, the following example could be used,
where frmContacts is the name of the data input form:
Private Sub cboContact_DblClick(Cancel As Integer)
On Error GoTo ErrHandler
Dim nContactID As Long
If (IsNull(Me!cboContact)) Then
Me!cboContact.Text = ""
Else
nContactID = Me!cboContact
Me!cboContact = Null
End If
DoCmd.OpenForm "frmContacts", , , , , acDialog, "New"
Me!cboContact.Requery
If (nContactID <> 0) Then
Me!cboContact = nContactID
End If
Exit Sub
ErrHandler:
MsgBox "Error in cboContact_DblClick( ) in " & Me.Name & " form." & _
vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
In the frmContacts form's OnLoad( ) event:
Private Sub Form_Load()
On Error GoTo ErrHandler
If ((Me.OpenArgs = "New") And Not IsNull(Me!txtID)) Then
DoCmd.GoToRecord , , acNewRec
End If
Exit Sub
ErrHandler:
MsgBox "Error in Form_Load( ) in " & Me.Name & " form." & _
vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.