D
dch3
I have a comboBox where I've provided the user with the ability to enter a
value not in the list and if it is present in the underlying recordsource,
select the value. (For example, if the comboBox has three columns - EMPLOYEE
NUMBER, EMPLOYEE NAME, EMPLOYEE INITIALS - where column(0) EMPLOYEE NUMBER is
the bound field and .limitToList is True, the user has the ability to enter
the EMPLOYEE INITIALS to enter the employee name.
In the code below and its associated comboBox, the user can type the Show
Name or Show Number. The Show Number is in the column that is bound, however
it is not displayed - only the Show Name. The code below allows the user to
enter the Show Number and if present will select the corresponding Show Name.
If the user, types a Show Name that is *NOT* present in the list, the code
successfully allows the user to enter a new record and then go to that record
in the comboBox.
The problem that I'm having is when the user enters the Show Number. The
code successfully opens the form that captures the new record, however upon
closing that form the new record is not displayed and I'm presented with the
'The please select an item from the list.' The new record is added to the
list.
How do I suppress the error message?
I've marked the problem area.
David H
Private Sub cboSelectShow_NotInList(NewData As String, Response As Integer)
'Code which selects the show based on show number is of my own doing
'Code which adds a new record curtesy of MS.
'Since the .LimitToList = True, this code allows the user to enter a job
number and locate the corresponding show from there
'Although the txtShowNumber is the first field in the combo list and the
bound field, we have to retreive the show name from
'the underlying table in order to move the list to that specific record
Dim strMsgText As String
Dim varResult As Variant
Dim rs As DAO.Recordset
Dim strShowName As String
On Error GoTo Err_cboSelectShow_NotInList
If ECount("txtShowName", "tblShowInformation", "txtShowNumber = '" &
NewData & "'") > 0 Then
Me.cboSelectShow = NewData
Response = acDataErrContinue
Me.cboSortOrder.SetFocus
Call cboSelectShow_AfterUpdate
Exit Sub
End If
strMsgText = ""
strMsgText = strMsgText & "The show number or name has not been set-up
in the database" & Chr(13) & Chr(13)
strMsgText = strMsgText & "Do you want to add the show?"
If MsgBox(strMsgText, vbInformation + vbYesNo + vbDefaultButton2) = vbNo
Then
strMsgText = "Please select a show from the list."
MsgBox strMsgText, vbInformation
Response = acDataErrContinue
Exit Sub
End If
DoCmd.Echo False
DoCmd.OpenForm "frmShowInformationDetail", , , , acFormAdd, acDialog,
NewData
DoCmd.Echo True
varResult = ECount("txtShowName", "tblShowInformation", "txtShowNumber =
'" & NewData & "'")
If IsNull(varResult) Then
' If the show was not added set the Response argument to suppress an
error message and undo changes.
strMsgText = "Please select a show from the list."
MsgBox strMsgText, vbInformation
Response = acDataErrContinue
Else
'-------------------------PROBLEM AREA-------------------------------------
strShowName = NewData
Me.cboSelectLoadList = strShowNam
'--------------------------------------------------------------------------------
Response = acDataErrAdded
End If
Exit_cboSelectShow_NotInList:
Exit Sub
Err_cboSelectShow_NotInList:
MsgBox getDefaultErrorMessage(Me.Name, "cboSelectShow_NotInList",
Err.Number, AccessError(Err.Number)), vbCritical
Resume Exit_cboSelectShow_NotInList
End Sub
value not in the list and if it is present in the underlying recordsource,
select the value. (For example, if the comboBox has three columns - EMPLOYEE
NUMBER, EMPLOYEE NAME, EMPLOYEE INITIALS - where column(0) EMPLOYEE NUMBER is
the bound field and .limitToList is True, the user has the ability to enter
the EMPLOYEE INITIALS to enter the employee name.
In the code below and its associated comboBox, the user can type the Show
Name or Show Number. The Show Number is in the column that is bound, however
it is not displayed - only the Show Name. The code below allows the user to
enter the Show Number and if present will select the corresponding Show Name.
If the user, types a Show Name that is *NOT* present in the list, the code
successfully allows the user to enter a new record and then go to that record
in the comboBox.
The problem that I'm having is when the user enters the Show Number. The
code successfully opens the form that captures the new record, however upon
closing that form the new record is not displayed and I'm presented with the
'The please select an item from the list.' The new record is added to the
list.
How do I suppress the error message?
I've marked the problem area.
David H
Private Sub cboSelectShow_NotInList(NewData As String, Response As Integer)
'Code which selects the show based on show number is of my own doing
'Code which adds a new record curtesy of MS.
'Since the .LimitToList = True, this code allows the user to enter a job
number and locate the corresponding show from there
'Although the txtShowNumber is the first field in the combo list and the
bound field, we have to retreive the show name from
'the underlying table in order to move the list to that specific record
Dim strMsgText As String
Dim varResult As Variant
Dim rs As DAO.Recordset
Dim strShowName As String
On Error GoTo Err_cboSelectShow_NotInList
If ECount("txtShowName", "tblShowInformation", "txtShowNumber = '" &
NewData & "'") > 0 Then
Me.cboSelectShow = NewData
Response = acDataErrContinue
Me.cboSortOrder.SetFocus
Call cboSelectShow_AfterUpdate
Exit Sub
End If
strMsgText = ""
strMsgText = strMsgText & "The show number or name has not been set-up
in the database" & Chr(13) & Chr(13)
strMsgText = strMsgText & "Do you want to add the show?"
If MsgBox(strMsgText, vbInformation + vbYesNo + vbDefaultButton2) = vbNo
Then
strMsgText = "Please select a show from the list."
MsgBox strMsgText, vbInformation
Response = acDataErrContinue
Exit Sub
End If
DoCmd.Echo False
DoCmd.OpenForm "frmShowInformationDetail", , , , acFormAdd, acDialog,
NewData
DoCmd.Echo True
varResult = ECount("txtShowName", "tblShowInformation", "txtShowNumber =
'" & NewData & "'")
If IsNull(varResult) Then
' If the show was not added set the Response argument to suppress an
error message and undo changes.
strMsgText = "Please select a show from the list."
MsgBox strMsgText, vbInformation
Response = acDataErrContinue
Else
'-------------------------PROBLEM AREA-------------------------------------
strShowName = NewData
Me.cboSelectLoadList = strShowNam
'--------------------------------------------------------------------------------
Response = acDataErrAdded
End If
Exit_cboSelectShow_NotInList:
Exit Sub
Err_cboSelectShow_NotInList:
MsgBox getDefaultErrorMessage(Me.Name, "cboSelectShow_NotInList",
Err.Number, AccessError(Err.Number)), vbCritical
Resume Exit_cboSelectShow_NotInList
End Sub