Error Message on Code

G

Guest

The following code (borrowed from www.functionx.com) has been adapted so I
may enter a new Agency in a field in a form if it is not in the tblagency.
Works great. However, if I select "No" in intAnswer the On Error GoTo runs
the Message "SomethingBadHappened" and I'm stuck. Is there a way that, if I
answer "No", give the user a chance to reenter a new Agency?
Thank you for any help!
Dan
-------------------------------------------------------------------

Private Sub agencyid_NotInList(NewData As String, Response As Integer)
On Error GoTo SomethingBadHappened

Dim rsttblagency As ADODB.Recordset
Dim intAnswer As Integer

intAnswer = MsgBox("Add " & NewData & " to the list of Agencies?", _
vbQuestion + vbYesNo)

If intAnswer = vbYes Then
Set rsttblagency = New ADODB.Recordset
rsttblagency.Open "tblAgency", CurrentProject.Connection, _
adOpenStatic, adLockOptimistic, adCmdTable

rsttblagency.AddNew
rsttblagency!Agency = NewData
rsttblagency.Update
Response = acDataErrAdded
Else
Response = acDataErrDisplay
End If

rsttblagency.Close
Set rsttblagency = Nothing


Exit Sub

SomethingBadHappened:
MsgBox "When trying to process this order, something bad happened" & _
vbCrLf & "Please contact the program vendor and " & _
"report the error as follows" & vbCrLf & _
"Error #: " & Err.Number & vbCrLf & _
"Description: " & Err.Description
Resume Next
End Sub
 
G

Guest

try just eliminating the Else clause by putting a ' in front of those two
lines

i.e.

' Else
' Response = acDataErrDisplay


I don't fully understand what your situation is....but with this change at
least you won't end up in the message box dead end.....plus if you change
your mind and don't like this approach it is simple enough to remove the two
' and return to where you were.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top