|
-
Oct 11th, 2001, 01:43 PM
#1
Thread Starter
New Member
Problematic SQL emmbedding
I just started using VB for my small Access project that seems to be expanding (by choice). I am just stuck with this bit of code. It is a search fuction. An Access Pop-up form is opens and there are three search fields... ID, Company and State... Well I've finally got it to work OR so I thought... it can search by the ID it's the other two that are giving me problems... I usually get a "Too Few Parameters. Expected <number>" error message. Help somebody out there... Here's my code....
Option Compare Database
Option Explicit
Private Sub cmdOK_Click()
On Error GoTo Err_cmdOK_Click
Dim stDocName As String, MySelect As String, MyFrom As String
Dim MyWhere As String, MyOrder As String, MyQry As String
Dim stLinkCriteria As String
Dim Mydb As Database
Dim MyRST As Recordset
MySelect = "SELECT DISTINCTROW Tours.ToursID, Tours.[Company Name], Tours.State, Tours.WorkPhone"
MyFrom = " FROM Tours"
MyOrder = " ORDER by Tours.[Company Name];"
MyWhere = " WHERE ((Not (Tours.ToursID) Is Null))"
If Not (IsNull(Me![ID])) Then
MyWhere = MyWhere & " AND (Tours.ToursID = " & Me![ID] & " )"
End If
If Not (IsNull(Me![Company])) Then
MyWhere = MyWhere & " AND (Tours.[Company Name] = " & Me![Company] & " )"
End If
If Not (IsNull(Me![State])) Then
MyWhere = MyWhere & " AND (Tours.State = " & Me![State] & " )"
End If
MyWhere = MyWhere & " AND (Tours.WorkPhone)"
MyQry = MySelect & MyFrom & MyWhere & MyOrder
Set Mydb = CurrentDb
Set MyRST = Mydb.OpenRecordset(MyQry)
DoCmd.Close acForm, "Find_Company_Sub"
If MyRST.RecordCount = 0 Then
MsgBox "No Records Found", vbOKOnly, "No Records"
Else
Forms![Find_Company].RecordSource = MySelect & MyFrom & MyWhere & MyOrder
End If
'stDocName = "Find_Company"
'stLinkCriteria = "[Company Name]=" & "'" & Me![Company] & "'"
'DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdOK_Click:
Exit Sub
Err_cmdOK_Click:
MsgBox Err.Description
Resume Exit_cmdOK_Click
End Sub
Private Sub cmdCancel_Click()
On Error GoTo Err_cmdCancel_Click
DoCmd.Close
Exit_cmdCancel_Click:
Exit Sub
Err_cmdCancel_Click:
MsgBox Err.Description
Resume Exit_cmdCancel_Click
End Sub
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|