Link to home
Start Free TrialLog in
Avatar of Daren Anderson, MSIS
Daren Anderson, MSISFlag for United States of America

asked on

Access97 - Too Few Parameters

I am writing a simple Access 97 database but in my form/subform, I keep getting this error - Too Few Parameters.  Expected 1.  I have a main form called "frmOrders"; its fields include a ClientID, OrderDate (hidden - set to todays date); then my subform on the bottom of the screen (linked by ClientID, OrderDate) has a drop down for AgentState, and some other fields like AmtOwed, Amt Due, etc. - the subforms Control Source is "qryfrmOrders" - based on the table "tblOrders" - the key on this is ClientID, AgentState, and OrderDate.  In this scenario, there is one client with multiple AgentStates.  Everything works fine until I use the dropdown on AgentState and a choice is made, then it comes up with the error Too Few Parameters. Expected 1.  According to Microsoft, they state there is a colunn name that is incorrect but I have looked all all of the names and just cannot come up with anything.  My code for the sql statement is below - I have this same exact code with different names on another form and works perfect.

Private Sub AgentState_AfterUpdate()
Dim db As DATABASE
Dim oRecordset As Recordset
Dim szSql As String
Dim szErr As String

Set db = CurrentDb()

On Error GoTo ErrorHandler

'ISADRA  Here the code will check the tables for duplicate records and inform the user if there is a duplicate
'And also will back up one record by sending ESC so that this duplicate is not entered.
If IsNull(Me![ClientID]) Then
  MsgBox "You must first select a ClientID#!", , " Client needed for File"
  SendKeys "{ESC}"
  Exit Sub
End If

If IsNull(Me![OrderDate]) Then
  MsgBox "You must first enter a OrderDate!!", , " OrderDate needed for File"
  SendKeys "{ESC}"
  Exit Sub
End If

 

szSql = "Select * from tblOrders where AgentState = " & Me![AgentState] & " and  ClientID = " & Me![ClientID] & _
        " and OrderDate = #" & Me![OrderDate] & "#"

If IsNull(Me![AgentState]) = True Then
    Exit Sub
End If

Set oRecordset = db.OpenRecordset(szSql)
If oRecordset.RecordCount > 0 Then
    MsgBox "The State code " & Me![AgentState] & " Already exsists in the  file for " & Me![OrderDate] & _
           "!!....Please Enter a valid State Code for this Client", vbExclamation, "State Code Already Exists"
           SendKeys "{ESC}"
End If


Exit_Sub:
  db.Close
  Exit Sub
 

ErrorHandler:
MsgBox Err.Description
GoTo Exit_Sub
 
End Sub
Avatar of rockiroads
rockiroads
Flag of United States of America image

where u use textboxes holding values
e.g

szSql = "Select * from tblOrders where AgentState = " & Me![AgentState] & " and  ClientID = " & Me![ClientID] & _
        " and OrderDate = #" & Me![OrderDate] & "#"


check that they have a valie
also u should be able to use

Me.AgentState

or AgentState.Value

check they all hold a value of some sort

instead of recordsets, u could make use of DLOOKUP as well
is NZ available on Acc97

NZ(field,"")

this checks for empty and null fields instead of you doing IsNull (which does not check for IsEmpty)

Hi CFProcessMgr,

Missing parameters usually points to a spelling error but I can't see anything obvious here.
Add code as below.

msgbox szsql  ' add this line and see if the sql string makes sense
 Set oRecordset = db.OpenRecordset(szSql)

Pete
SOLUTION
Avatar of Pigster14
Pigster14
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daren Anderson, MSIS

ASKER

I have done a step thru in the code and all of my fields in the sql statement are filled in.  Also, I have never had a lot of luck with DLOOKUP so I dont use it.
can u do this

szSql = "Select * from tblOrders where AgentState = " & Me![AgentState] & " and  ClientID = " & Me![ClientID] & _
        " and OrderDate = #" & Me![OrderDate] & "#"

'add this line
debug.print szSql

then look in immediate window, copy/paste that sql and run in query editor

ah ha, just saw pigster's post, Im thinking along the same lines as him

CFProcessMgr,
>  subform on the bottom of the screen (linked by ClientID, OrderDate)
> has a drop down for AgentState,
Just noticed this while re-reading...
So

szSql = "Select * from tblOrders where AgentState = " & Me![AgentState] & " and  ClientID = " & Me.Parent.[ClientID] & _
        " and OrderDate = #" & Me.Parent.[OrderDate] & "#"


Pete
I changed the SQL statement to add the .Parent as shown above - no difference.  When I tried Pigster's suggestion, I get this in the inputbox = Select * from tblOrders where AgentState = AZ001 and  ClientID = 6127899000 and OrderDate = #5/16/2006#.  I put this in a new query and try to run it - I get an input box up asking for AZ001 - just like it is not recognized and then no matter what I put in the inputbox, I get this error - This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables. (Error 3071)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Have you looked at the actual RecordSource property for the AgentState drop-down. In my experience, it could be that you have something in the Criteria for this query, who's name cannot be resolved, such as a field on a form that is currently closed. Alternatively, look at the Parameter box from the Query menu in the query design view to see if an unexpected parameter has 'crept in'

Just my tuppence worth.

Regards.