Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error trapping

Status
Not open for further replies.

teebird

Technical User
Dec 11, 2001
239
Hi Everyone

I have this sub and want to have a custom error message come up when the user clicks in an empty record. This is one continuous form.

Private Sub Details_Click()
Dim gstrWhereFileNo As String

gstrWhereFileNo = "[FileNo] = " & Me!FileNo
DoCmd.OpenForm FormName:="frmHearingForm", WhereCondition:=gstrWhereFileNo
DoCmd.Close acForm, Me.name
Forms!frmHearingForm.SetFocus
End Sub

Private Sub Hearing_Date_DblClick(Cancel As Integer)
Details_Click
End Sub

Any suggestions.

Thanks
tee
 
Here is your code with some custome error trapping!

I can't remember the Err no for a null record (is it 51?) so in my Select Case ERR statement, I have used Err = 51 as an example only. Insert the error trapping and if the Case Else pops up, it'll tell you the correct Error number. simply step back into the code and replace Case 51 with Case [correct Number]:

=-=-=-=-=-==Codey Bit=-=-=-=-=-=-=

Code:
Private Sub Details_Click()
   On Error Goto Details_Click_Err
   Dim gstrWhereFileNo As String

   gstrWhereFileNo = "[FileNo] = " & Me!FileNo
   DoCmd.OpenForm FormName:="frmHearingForm", WhereCondition:=gstrWhereFileNo
   DoCmd.Close acForm, Me.name
   Forms!frmHearingForm.SetFocus
Details_Click_Exit:
   On Error Resume Next
   Exit Sub
Details_Click_Err:
   Select Case Err
      Case 51 'Presummed Error No for Null Record/0 Records 
          Msgbox "There are no records available at this time!", 16, "No Records"
      Case Else
         Msgbox Error$,16,"Error no " & Err & " in Details_Click()"
   End Select
End Sub

=-=-=-=-=-==End Of Codey Bit=-=-=-=-=-=-=

Hope this helps

birklea
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top