Access97 - Too Few Parameters
Posted on 2006-05-16
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"
If IsNull(Me![OrderDate]) Then
MsgBox "You must first enter a OrderDate!!", , " OrderDate needed for File"
szSql = "Select * from tblOrders where AgentState = " & Me![AgentState] & " and ClientID = " & Me![ClientID] & _
" and OrderDate = #" & Me![OrderDate] & "#"
If IsNull(Me![AgentState]) = True Then
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"