473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Help with my SQL statement!!!!!!!!

52
Im using vb and access to for my project. Im trying to use this code in order to show all the payments made to a specific staff.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.  
  3. Dim strSQL As String
  4.  
  5.     strSQL = "SELECT * FROM Staff "
  6.     strSQL = strSQL & "WHERE Firstname = " & txtName.Text
  7.  
  8.  Set dbmyDB = OpenDatabase("E:\skol\A2 Computing\Speedy Pizza database.mdb")
  9.  Set rsStaff = dbmyDB.OpenRecordset(strSQL, dbOpenDynaset)
  10.  
  11.     If Not rsStaff.EOF Then rsStaff.MoveFirst
  12.     lstRecord.Clear
  13.  
  14.     Do Until rsStaff.EOF
  15.     lstRecord.AddItem rsStaff!Firstname & " " & rsStaff!Lastname & vbTab & rsStaff!StaffID
  16.     lstRecord.ItemData(lstRecord.NewIndex) = rsStaff!StaffID
  17.     rsStaff.MoveNext
  18.     Loop
  19. End Sub
I keep getting an error on the line " Set rsStaff = dbmyDB.OpenRecordset(strSQL, dbOpenDynaset)". It says 'Too few parameters. Expected one'
Im not very good with SQL statements so it's hard for me to solve. I would appreciate it if anyone has any good answers.
THANK U
Feb 8 '08 #1
5 1083
QVeen72
1,445 Expert 1GB
Hi,

I guess, your First Name Field in Database must be text.. Wrap the name with Single Quotes:

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM Staff " 
  2. strSQL = strSQL & " WHERE Firstname = '" & txtName.Text & "'"
  3.  
Regards
Veena
Feb 8 '08 #2
THEAF
52
Hi,

I guess, your First Name Field in Database must be text.. Wrap the name with Single Quotes:

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM Staff " 
  2. strSQL = strSQL & " WHERE Firstname = '" & txtName.Text & "'"
  3.  
Veena
sorry i forgot to mention that i wanted to put txtSname.text after txtname.text so that it will show 1 person with that name and not anyone with the same first name. sorry for the trouble but how do i put this in. your improvement worked. but when i tried to fix it so that Sname comes up the list box just clears. Could you please help me.
strSQL = strSQL & " WHERE Firstname = '" & txtName.Text & "'"
Feb 8 '08 #3
QVeen72
1,445 Expert 1GB
Hi,

Is it that you want to query with both Firstname and secondname...?
Try this :

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM Staff " 
  2. strSQL = strSQL & " WHERE Firstname = '" & txtName.Text & "'"
  3. strSQL = strSQL & "  And LastName = '" & txtSName.Text & "'"
  4.  
  5.  
Regards
Veena
Feb 8 '08 #4
THEAF
52
Hi,


Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM Staff " 
  2. strSQL = strSQL & " WHERE Firstname = '" & txtName.Text & "'"
  3. strSQL = strSQL & "  And LastName = '" & txtSName.Text & "'"
  4.  
  5.  
Regards
Veena
Again sorry about this but I'm getting the same error again on the line
Expand|Select|Wrap|Line Numbers
  1.  Set rsPayment = dbmyDB.OpenRecordset(strSQL, dbOpenDynaset)
that its too few parameters
Feb 8 '08 #5
QVeen72
1,445 Expert 1GB
Again sorry about this but I'm getting the same error again on the line
Expand|Select|Wrap|Line Numbers
  1.  Set rsPayment = dbmyDB.OpenRecordset(strSQL, dbOpenDynaset)
that its too few parameters
Hi,

Check the FieldNames in Database..

Regards
Veena
Feb 9 '08 #6

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

Similar topics

46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
5
by: WindAndWaves | last post by:
Hi Team The function below searches all the tables in a database. However, if subsearch = true then it searches all the objects listed in a recordset (which are all table names). I thought to...
11
by: Scott C. Reynolds | last post by:
In VB6 you could do a SELECT CASE that would evaluate each case for truth and execute those statements, such as: SELECT CASE True case x > y: dosomestuff() case x = 5: dosomestuff() case y >...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
2
by: Greg Corradini | last post by:
Hello All, A few weeks ago, I wrote two scripts using mx.ODBC on an Access DB. Among other things, both scripts create new tables, perform a query and then populate the tables with data in a...
6
by: redashley40 | last post by:
This is my first attempt in SQL and PreparedStatement I have add the PreparedStatement and I'm not to sure if I'm doing it correctly. When I do a test run on Choose 1 ,or 2 I get this error. Error...
2
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
0
by: RCapps | last post by:
When running the below SQL Query I keep getting the following error: Server: Msg 4924, Level 16, State 1, Line 1 ALTER TABLE DROP COLUMN failed because column 'ContractDef' does not exist in table...
2
by: nleake | last post by:
Hey, I've been trying to use Python to help me with some DNA sequencing work. I've figured out how to use Biopython for the importing work; however, I need some python code to help me remove a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...

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.