Here is my code:
Code:
Private Sub txtProvider_Number_AfterUpdate()
Dim strSQL As String
Dim rs As DAO.Recordset
strSQL = "SELECT [prov1].LAST_NAME, [prov1].COUNTY, [prov1].NAME,
[prov1].IPA_ID, [prov1].FIRST_NAME, [prov1].ADDRESS_LINE_1,
[prov1].ADDRESS_LINE_2, [prov1].CITY, [prov1].STATE, [prov1].ZIP_CODE,
[prov1].PHONE_NUMBER FROM [prov1] WHERE " & _
"[prov1].SEQ_PROV_ID=" & Me.Provider_Number
Set rs = CurrentDb.OpenRecordset(strSQL)
rs.MoveLast
rs.MoveFirst
If rs.RecordCount > 0 Then
Me.txtProvider_Last_Name = rs.Fields![LAST_NAME]
Me.txtProvider_First_Name = rs.Fields![FIRST_NAME]
Me.txtProvider_Address = rs.Fields![ADDRESS_LINE_1]
Me.txtProvider_Address2 = rs.Fields![ADDRESS_LINE_2]
Me.txtProvider_City = rs.Fields![CITY]
Me.txtProvider_State = rs.Fields![STATE]
Me.txtProvider_Zip = rs.Fields![ZIP_CODE]
Me.txtProvider_Phone = rs.Fields![PHONE_NUMBER]
Me.txtCounty = rs.Fields![COUNTY]
Me.txtIPA_Name = rs.Fields![Name]
Me.txtIPA_Number = rs.Fields![IPA_ID]
End If
rs.Close
Set rs = Nothing
End Sub
J_Goddard via AccessMonster.com said:
If your error handling code is near the beginning of the procedure, the
chances are that it is being executed whether an error occurs or not. Of
course, it could also be that there is something else wrong, and that the
errors are genuine, particularly if the error number is non-zero.
Can you post your code?
Yepp wrote:
Thanks for the help; however, now that I have moved the code near the
beginning of my procedure, the error message comes up regardless of the
number that is typed in. How can I prevent that?
[quoted text clipped - 25 lines]
Resume Exit_Trapping
End Sub
Message posted viahttp://
www.accessmonster.com- Hide quoted text -
- Show quoted text -
Try something like this
Private Sub txtProvider_Number_AfterUpdate()
On Error GoTo txtProvider_Number_Error
Dim strSQL As String
Dim rs As DAO.Recordset
strSQL = "SELECT [prov1].LAST_NAME, [prov1].COUNTY, [prov1].NAME,
[prov1].IPA_ID, [prov1].FIRST_NAME, [prov1].ADDRESS_LINE_1,
[prov1].ADDRESS_LINE_2, [prov1].CITY, [prov1].STATE,
[prov1].ZIP_CODE,
[prov1].PHONE_NUMBER FROM [prov1] WHERE " & _
"[prov1].SEQ_PROV_ID=" & Me.Provider_Number
Set rs = CurrentDb.OpenRecordset(strSQL)
With rs
.MoveFirst
If .RecordCount > 0 Then
txtProvider_Last_Name = ![LAST_NAME]
txtProvider_First_Name = ![FIRST_NAME]
txtProvider_Address = ![ADDRESS_LINE_1]
txtProvider_Address2 = ![ADDRESS_LINE_2]
txtProvider_City = ![CITY]
txtProvider_State = ![STATE]
txtProvider_Zip = ![ZIP_CODE]
txtProvider_Phone = ![PHONE_NUMBER]
txtCounty = ![COUNTY]
txtIPA_Name = ![Name]
txtIPA_Number = ![IPA_ID]
End If
End With
txtProvider_Number_End:
rs.Close
Set rs = Nothing
Exit Sub
txtProvider_Number_Error:
If Err.Number = 3021 Then 'No current record
MsgBox Err.Number & Err.Description
Resume txtProvider_Number_End
Else 'Some other error
MsgBox Err.Number & Err.Description
Resume Next
End Sub
Hope this helps,
Chris M.