473,472 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Too Few Parameters Error Confusion

1 New Member
I am trying to design a simple database that has one form (frmSessions) where a person will enter sessions for an upcoming conference we are planning. The purpose of the form is to prevent us from double-booking a room. The form has 7 fields that should get saved to a table called tblSessions. The user must enter the Session Title, Choose a date from a list box, choose a room from a list box, and then Choose a start time from a list box. I have created a "Before Update" event on the start time control that should check for an existing record in the tblSessions table. Basically if the query returns any record and error msg should appear saying CONFLICT. I keep getting an error of "Too few parameters - 3 expected" on the line "Set rs = dbs.OpenRecordset(strSQL, dbOpenSnapshot)"

Any suggestions on what I am doing wrong? Below is the complete code for the trigger...

Expand|Select|Wrap|Line Numbers
  1. Private Sub LstSessionStart_BeforeUpdate(Cancel As Integer)
  2.  
  3. Dim dbs As DAO.Database, rs As DAO.Recordset, strSQL As String
  4.  
  5.  
  6. Set dbs = CurrentDb()
  7. strSQL = "SELECT COUNT (sessionID) AS Conflicts FROM tblSessions WHERE (([tblSessions].SessionDate = Me.LstSessionDate)AND ([tblSessions].SessionRoom = Me.CboSessionRoom) AND (Me.LstSessionStart >= [tblSessions].SessionStart) AND (Me.LstSessionStart <= [tblSessions].SessionEnd))"
  8. Set rs = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
  9.  
  10. If rs.RecordCount <> 0 And Me.NewRecord Then
  11. MsgBox "There is a conflict with this room on this date at this time."
  12. Cancel = True
  13. Me.Undo
  14. End If
  15.  
  16. End Sub
Mar 23 '16 #1
1 1101
Seth Schrock
2,965 Recognized Expert Specialist
The problem is that the SQL engine doesn't recognise the control names. You need to exclude them from being inside the quotes using concatenation so that the values that are in the controls get used. Based on the error message, there may be some misspelled field names as well, I don't know.

Try the following:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT COUNT (sessionID) AS Conflicts " & _
  2.          "FROM tblSessions WHERE (([tblSessions].SessionDate = #" & Me.LstSessionDate & _
  3.          "#) AND ([tblSessions].SessionRoom = " & Me.CboSessionRoom & _
  4.          ") AND (" & Me.LstSessionStart & ">= [tblSessions].SessionStart) AND (" & _
  5.          Me.LstSessionStart & "<= [tblSessions].SessionEnd))"
Mar 23 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dennis | last post by:
I created a table adapter on an xsd that uses 4 basic stored procedures for select, update, insert, delete. Then I created an aspx page with an object data source that uses the table adapter and a...
2
by: Hexman | last post by:
Hello All, Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in my update statement and when trying...
2
by: MirzaSila | last post by:
Hear is the part of code: Dim db As DAO.Database Dim rst As DAO.Recordset Set db = CurrentDb() Set rst = db.OpenRecordset("SELECT FirstName FROM People WHERE LastName = " & LastName & "") ...
0
by: crimirish | last post by:
I've been trying to debug this too few parameters error, any help? Help is the code strSQL = "SELECT ((H.A/d.r)*100) AS , ((M.B/d.r)*100) AS Normal, ((L.C/d.r)*100) AS " & _ "FROM (select...
8
by: priyankalakhe | last post by:
Hi, I'm new to Automation and am currently trying a code from msdn http://msdn2.microsoft.com/en-us/library/aa155776(office.10).aspx to automate a word application(Office 2003) in VC++...
2
by: darkhat01 | last post by:
I am running a cross tab on a Union query and I am getting and error. The Microsoft Jet database engine does not recognize '!!' as a valid field name or expression. Here is the SQl code: ...
2
by: JoeNinja | last post by:
Im failing to update the an MS ACcess. I will appreciate Your advice. I get the error below Warning: odbc_exec() : SQL error: Too few parameters. Expected 1., SQL state 07001 in SQLExecDirect in...
4
by: gmazza | last post by:
Hi there, I am trying to insert 4 fields into a table grabbing the 4 fields from a form, here is my code: Private Sub LastPaymentAmount_AfterUpdate() Dim CurrentProject As DAO.Database Set...
3
by: MLH | last post by:
Set rstTemp = .OpenRecordset(dbOpenSnapshot) Execution of the above line gives me a "Too few parameters" error. The line is preceeded by another line I thought would make it work... With...
1
by: Aruna Dalvi | last post by:
Hi friend Please tell me why this error is occured ERROR Too few parameters. Expected 22. Cod Dim InsertString As String = "INSERT INTO TableHR1...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.