Full Version: Same Song; Second Verse
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
StarsFan
Well I'm having a good night. I have another "Too Few Parameters" Expected 1 error message

Below is the code I'm trying to get to work. If I leave out the db.OpenRecordset part, it works. If I leave it in I get the error message. I would appreciate it if someone could throw some suggestions my way.

If Me.chkSectionEquipment = True Then
If Trim(Nz(Me.txtEquip, "")) = "" Then
Eval ("Msgbox('Equipment Name Is [email=Missing@Before]Missing@Before[/email] I can filter the Orders List " & _
"you must type an Equipment name!@@',0,'AMC Database Message System')")
Me.txtEquip.SetFocus
Exit Sub
Else
Dim db As DAO.Database, rs As DAO.Recordset
Set db = CurrentDb
Dim stS As String
stS = "SELECT * FROM Orders WHERE Orders.Equipment" & _
" LIKE ""*"" & Forms![frmOrdersFilter]![txtEquip] & ""*"""

Set rs = db.OpenRecordset(stS) 'Here is where it highlights for the too few parameters error

If rs.RecordCount = 0 Then
Eval ("Msgbox('There Are No Matching Records!@There are no matching Orders for the criteria(s) " & _
"you have entered!@@',0,'No Matching Orders')")
Else
Forms![frmOrdersNavigator]![frmOrderssub].Form.RecordSource = stS
Forms![frmOrdersNavigator]![frmOrderssub].Form.Refresh
DoCmd.Close acForm, "frmOrdersFilter"
Exit Sub
End If
End If
End If
R. Hicks
Try changing these lines:
CODE
stS = "SELECT * FROM Orders WHERE Orders.Equipment" & _
" LIKE ""*"" & Forms![frmOrdersFilter]![txtEquip] & ""*"""

Change them to:
CODE
stS = "SELECT * FROM Orders WHERE Orders.Equipment" & _
" LIKE '*'" & Forms![frmOrdersFilter]![txtEquip] & "'*'"


RDH
StarsFan
Thanks...again, Mr. Hicks.

I'm now getting a sytax error. Missing Operator in query expression.

Any thoughts?

Shane
R. Hicks
Is the form open that is being referenced when the query is executed ???

RDH
StarsFan
Yes.

Shane
mishej
Perhaps it is a Null value issue?

I did a slight re-write that you could try:
CODE
If Me!chkSectionEquipment = True Then
  If Len(Me!txtEquip & vbNullString) = 0 Then
    Eval ("Msgbox('Equipment Name Is Missing@Before I can filter the Orders List " & _
      "you must type an Equipment name!@@',0,'AMC Database Message System')")
    Me!txtEquip.SetFocus
    Exit Sub
  Else
    Dim db As DAO.Database, rs As DAO.Recordset
    Dim stS As String

    Set db = CurrentDb
    stS = "SELECT * FROM Orders WHERE Orders.Equipment" & _
          " LIKE '*'" & IIf(IsNull(Me![txtEquip]), "", "'*'")

    Set rs = db.OpenRecordset(stS) 'Here is where it highlights for the too few parameters error

    If rs.RecordCount = 0 Then
      Eval ("Msgbox('There Are No Matching Records!@There are no matching Orders for the criteria(s) " & _
        "you have entered!@@',0,'No Matching Orders')")
    Else
      With Forms![frmOrdersNavigator]![frmOrderssub].Form
        .RecordSource = stS
        .Refresh            ' this is probably unnecessary
        DoCmd.Close acForm, "frmOrdersFilter"
        Exit Sub
      End With
    End If

    rs.Close
    Set rs = Nothing
    Set db = Nothing
  End If
End If

If the error occurs at the OpenRecordset() call then it indicates that the SQL is incorrect. Copy
the SQL to a new query window and try to run it (with the appropriate form open). The cursor will
be positioned to the area where the error occurs.
cheekybuddha
Do you guys want the extra quote marks in there?

Surely you'll end up with a string like:

...Like '*'CompareText'*'

(which I would imagine won't work) rather than:

...Like '*CompareText*'


I would try:
CODE
stS = "SELECT * FROM Orders WHERE Orders.Equipment" & _
" LIKE '*" & Forms![frmOrdersFilter]![txtEquip] & "*'"



hth,

d
mishej
Yes I think you are correct. It's "air code" and untested. Or maybe a better cop-out is " it was left as an exercise for the user"!
cheekybuddha
lol John, and I fell for it!


laugh.gif

d
StarsFan
Thanks guys for you help.

d (CheekyBuddha), code is working fine. I really appreciate all of you lending a helping hand.

Shane
argeedblu
Shane,

It looks like you have had some good for this one, as well. I am only responding to pass along a tip I found helpful for working with constructed sql strings. When I run into this sort of problem I put in a breakpoint at the offending place and then run the code again. When it stops, I inspect the value that has been assigned to the sql string variable. Seeing the actual sql string that I am trying to execute will usually help me decipher the problem.

That's not to suggest that you shouldn't continue to post this sort of problem on UA. It's just a way that might help towards a solution.

Glenn
StarsFan
Thank you for the tip Glenn. This is certainly a never ending process of learning, especially when you don't do this for a living. My family and I have a small business which causes you to do a lot of things on your own. Designing a database for the company, is one of those things. I'm self taught and think to myself how far I've come since I first picked up Access, then days like yesterday happen and realize how far I still have to go. Delimiters bite me in my back pockets more than anything. I have yet to read anything that really helps me to "get it."

Thank goodness for UA. It has made the most difference in getting Stage 1 of my project done. The folks here are so knowledgeable and don't let their ego's get in the way of helping.

Thanks again,
Shane
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.