klwu
Brainy!!
- Local time
- Tomorrow, 06:27
- Joined
- Sep 13, 2004
- Messages
- 47
The following is my piece of code for a search form, however it is not working, sometimes it comes out syntax error, sometimes it comes out OpenForm has been cancelled. Please someone guide me on this. Thanks a bunch!
Code:
Private Sub cmdSearch_Click()
On Error GoTo Err_cmdSearch_Click
Dim sSql As String
sSql = "1 = 1"
If Not IsNull(cmbComRef) And cmbComRef <> "" Then
sSql = sSql & " AND ComRef LIKE '*" & cmbComRef & "*'"
End If
If Not IsNull(txtRefNo) And txtRefNo <> "" Then
sSql = sSql & " AND RefNo = " & txtRefNo
End If
If Not IsNull(txtName) And txtName <> "" Then
sSql = sSql & " AND Name = " & txtName
End If
If Not IsNull(txtIPAdd) And txtIPAdd <> "" Then
sSql = sSql & " AND IP = " & txtIPAdd
End If
If Not IsNull(txtPortNo) And txtPortNo <> "" Then
sSql = sSql & " AND PortNo = " & txtPortNo
End If
If Not IsNull(txtNetworkID) And txtNetworkID <> "" Then
sSql = sSql & " AND NetworkID = " & txtNetworkID
End If
DoCmd.OpenForm "SearchList", , , sSql
Exit_cmdSearch_Click:
Exit Sub
Err_cmdSearch_Click:
MsgBox Err.Description
Resume Exit_cmdSearch_Click
End Sub