| View previous topic :: View next topic |
| Author |
Message |
KaleKYlssen Newbie
Joined: 31 Jan 2004 Posts: 19
|
Posted: Feb 3rd, 2004 01:29 PM Post subject: sql statement |
|
|
what would sql statement be if i wanted to return a record from a database that has a double key, for a single key record i have this
| Code: |
sqlstaff = "SELECT * FROM Staff WHERE StaffId = " & cboStaff.Text
|
but on my new form i want to open the record that has staffid and the weekstarting fields linked, the staffid will be selected from a combo box but the week will be from a textbox |
|
| Back to top |
|
Avis Junior Poster

Joined: 07 Oct 2003 Posts: 510 Location: India
|
|
| Back to top |
|
KaleKYlssen Newbie
Joined: 31 Jan 2004 Posts: 19
|
Posted: Feb 3rd, 2004 01:54 PM Post subject: |
|
|
i've done that but now it says no value given for one or more required parameters and highlights rsweek.open line
| Code: |
Private Sub cboStaff_Click()
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Elco.mdb"
sqlefficiency = "SELECT * FROM Staff WHERE StaffID = " & cboStaff.Text & " AND WeekStarting = '" & cboWeek.Text & "'"
rsweek.Open sqlefficiency, ConnString, adOpenKeyset, adLockOptimistic, adCmdText
rsweek.MoveFirst
txtMotor.Text = rsweek.Fields("TimeTaken") / rsweek.Fields("MotorsMade") * 60
rsweek.Close
|
|
|
| Back to top |
|
Avis Junior Poster

Joined: 07 Oct 2003 Posts: 510 Location: India
|
|
| Back to top |
|
KaleKYlssen Newbie
Joined: 31 Jan 2004 Posts: 19
|
Posted: Feb 3rd, 2004 02:14 PM Post subject: |
|
|
still no look i'll post the entire code for that form if it will help
| Code: |
Dim rsstaff As ADODB.Recordset
Dim cn As ADODB.Connection
Dim rsweek As ADODB.Recordset
Private Sub cboStaff_Click()
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Elco.mdb"
sqlefficiency = "SELECT * FROM Efficiency WHERE StaffID = " & cboStaff.Text & " AND WeekStarting = " & cboWeek.Text & ""
rsweek.Open sqlefficiency, ConnString, adOpenKeyset, adLockOptimistic, adCmdText
rsweek.MoveFirst
txtMotor.Text = rsweek.Fields("TimeTaken") / rsweek.Fields("MotorsMade") * 60
rsweek.Close
End Sub
Private Sub cmdExit_Click()
Unload Me
frmMenu.Show
End Sub
Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rsstaff = New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Elco.mdb"
rsstaff.Open "Staff", cn.ConnectionString, adOpenKeyset, adLockPessimistic, adCmdTable
rsstaff.MoveFirst
Do Until rsstaff.EOF = True
cboStaff.AddItem rsstaff.Fields("StaffId")
rsstaff.MoveNext
Loop
rsstaff.Close
Set rsweek = New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Elco.mdb"
rsweek.Open "Efficiency", cn.ConnectionString, adOpenKeyset, adLockPessimistic, adCmdTable
rsweek.MoveFirst
Do Until rsweek.EOF = True
cboWeek.AddItem rsweek.Fields("WeekStarting")
rsweek.MoveNext
Loop
rsweek.Close
End Sub
|
|
|
| Back to top |
|
Avis Junior Poster

Joined: 07 Oct 2003 Posts: 510 Location: India
|
Posted: Feb 4th, 2004 10:54 AM Post subject: |
|
|
Hi!
Try this one:
| Code: | Dim rsstaff As ADODB.Recordset
Dim cn As ADODB.Connection
Dim rsweek As ADODB.Recordset
Private Sub cboStaff_Click()
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Elco.mdb"
sqlefficiency = "SELECT * FROM Efficiency WHERE StaffID = " & cboStaff.Text & " AND WHERE WeekStarting = '" & cboWeek.Text & "'"
rsweek.Open sqlefficiency, ConnString, adOpenKeyset, adLockOptimistic, adCmdText
rsweek.MoveFirst
txtMotor.Text = rsweek.Fields("TimeTaken") / rsweek.Fields("MotorsMade") * 60
rsweek.Close
End Sub
Private Sub cmdExit_Click()
Unload Me
frmMenu.Show
End Sub
Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rsstaff = New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Elco.mdb"
rsstaff.Open "Staff", cn.ConnectionString, adOpenKeyset, adLockPessimistic, adCmdTable
rsstaff.MoveFirst
Do Until rsstaff.EOF = True
cboStaff.AddItem rsstaff.Fields("StaffId")
rsstaff.MoveNext
Loop
rsstaff.Close
Set rsweek = New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Elco.mdb"
rsweek.Open "Efficiency", cn.ConnectionString, adOpenKeyset, adLockPessimistic, adCmdTable
rsweek.MoveFirst
Do Until rsweek.EOF = True
cboWeek.AddItem rsweek.Fields("WeekStarting")
rsweek.MoveNext
Loop
rsweek.Close
End Sub |
_________________ Code Snippets, Tutorials, Utilities, Controls
Low cost Web Hosting
Hosting starts at as low as $4 per year!
Always follow posting guidelines
Put your VB code in [vb ] your code [ /vb] tags! |
|
| Back to top |
|
KaleKYlssen Newbie
Joined: 31 Jan 2004 Posts: 19
|
Posted: Feb 4th, 2004 01:24 PM Post subject: |
|
|
| when i use that code it states a syntax error, but when i remove the WHERE from the sql statement that error doesn't occur but the no value error still happens. :huh: |
|
| Back to top |
|
KaleKYlssen Newbie
Joined: 31 Jan 2004 Posts: 19
|
Posted: Feb 4th, 2004 01:32 PM Post subject: |
|
|
| heres the project so far so you can check the database for the error (theres bound to be some) |
|
| Back to top |
|
Andir Centurion

Joined: 21 Dec 2003 Posts: 184 Location: Chicago Area
|
Posted: Feb 4th, 2004 03:06 PM Post subject: |
|
|
One very important thing to not when working with SELECT statements is the type of data your pulling. I haven't pulled the data yet, but if your dealing with dates and times, surround your date with # signs:
.."WHERE someDate = #" & myDate & "#"
The same hold true with string values (char/varchar). Unless you explicitly say in the database that the variable type is a number(int/long/double), you should put a ' around the data:
.."WHERE someValue = '" & myValue & "'"
This might be the problem your running into as Avis was showing you with the ' signs he added.
Is the StaffID an AutoNumber field? or a "char" field? Is the WeekStarting a date? _________________ If you happen to see little people sitting on your desk...don't tell anyone or they might think your crazy too. |
|
| Back to top |
|
KaleKYlssen Newbie
Joined: 31 Jan 2004 Posts: 19
|
Posted: Feb 5th, 2004 04:53 AM Post subject: |
|
|
The staffid field is text but the weekstarting is a date, i'm at college at the moment so will try your sugestions when i get home
Thanks |
|
| Back to top |
|
KaleKYlssen Newbie
Joined: 31 Jan 2004 Posts: 19
|
Posted: Feb 5th, 2004 02:09 PM Post subject: |
|
|
| ok that worked thanks alot for your help |
|
| Back to top |
|
|