Error Handling, Don't know how?

furnitureheaven

Registered User.
Local time
Today, 16:00
Joined
Aug 5, 2008
Messages
36
hi
i am writing a code in select record from table, but if user enter letter or $ same its produce error, i want to do some error handling, but don't know how to do this.
could anyone guide me here, my code is like this.

Code:
On Error GoTo E_Handle
Forms!LegFile!frmRefNo.SetFocus
Dim rs As DAO.Recordset
Dim SQLtext As String
'Dim db As DAO.Database
'Dim rs As Recordset
'Dim myvalue As String
Set rs = CurrentDb.OpenRecordset("SELECT FRefNo FROM LegLook Where (((Ftype)= " & [Forms]![LegFile].[Combo8] & "));")
'Set rs = CurrentDb.OpenRecordset("SELECT FRefNo FROM LegLook;")
E_Handle:
    Select Case Erro.Number
    Case 7112
    MsgBox "Please Select File Type", vbOKOnly, Err.Number
    End Select
SQLtext = rs("FRefNO").Value
frmRefNo = SQLtext
rs.Close
Set rs = Nothing

Thanks
 
firstly, because the contents of your combo box will be treated as strings you will need to encompass your criteria in quotes

VIS

Where FType = '" & criteria & "'"

David
 
firstly, because the contents of your combo box will be treated as strings you will need to encompass your criteria in quotes

VIS

Where FType = '" & criteria & "'"

David

This is a number field in Database if i do as you said, its says datatype mis match critria.

how we could error handling here.
 
Ok

Where are you calling this code from? If it is on the OnClick or AfterUpdate of the combo box then you need to slim down your code.


Code:
Dim rs As DAO.Recordset
Dim SQLtext As String
Set rs = CurrentDb.OpenRecordset("SELECT FRefNo FROM LegLook Where Ftype= " & Me.Combo8 )
If Not Rs.EOF And Not Rs.BOF Then
   SQLtext = rs("FRefNO")
   Rs.Close
End If
frmRefNo = SQLtext
Set rs = Nothing

A more easy way is to use a DLookup
SQLText = DLookup("FRefNo","LegLook","Ftype=" & Me.Combo8)
 

Users who are viewing this thread

Back
Top Bottom