recordset?

R

Russ Hromyko

Can anyone tell me why this is happening, when I use an actual number, 47731
for the [Hours] everything works, but when I use Me.cboHours I get an error
message? What am I missing and how do I make Me.cboHours work? When I hit
debug on the error message it points to the recordset (Set rs = ). Below
the dotted line is not part of the code, it's the code I want to work.


Private Sub cboHours_AfterUpdate()
Dim sqlStr As String
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb

sqlStr = "SELECT * FROM dbo_LaserMachineMaintLog WHERE [Laser Machine] =
" & _
"'" & Me.cboLaserMachine & "' " & "AND [Hours] = 47731"

Set rs = db.OpenRecordset(sqlStr, dbOpenDynaset, dbSeeChanges)

'---------------------------------------------------------------------------------------------------------------------------------------------


sqlStr = "SELECT * FROM dbo_LaserMachineMaintLog WHERE [Laser Machine] = " &
_
"'" & Me.cboLaserMachine & "' " & "AND [Hours] = " & Me.cboHours

Set rs = db.OpenRecordset(sqlStr, dbOpenDynaset, dbSeeChanges)
 
D

Dirk Goldgar

In
Russ Hromyko said:
Can anyone tell me why this is happening, when I use an actual
number, 47731 for the [Hours] everything works, but when I use
Me.cboHours I get an error message? What am I missing and how do I
make Me.cboHours work? When I hit debug on the error message it
points to the recordset (Set rs = ). Below the dotted line is not
part of the code, it's the code I want to work.

Private Sub cboHours_AfterUpdate()
Dim sqlStr As String
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb

sqlStr = "SELECT * FROM dbo_LaserMachineMaintLog WHERE [Laser
Machine] = " & _
"'" & Me.cboLaserMachine & "' " & "AND [Hours] = 47731"

Set rs = db.OpenRecordset(sqlStr, dbOpenDynaset, dbSeeChanges)

'---------------------------------------------------------------------------------------------------------------------------------------------


sqlStr = "SELECT * FROM dbo_LaserMachineMaintLog WHERE [Laser
Machine] = " & _
"'" & Me.cboLaserMachine & "' " & "AND [Hours] = " &
Me.cboHours
Set rs = db.OpenRecordset(sqlStr, dbOpenDynaset, dbSeeChanges)

What error message are you getting, and what are the values of cboHours
and sqlStr when you get it?
 
G

Guest

Not sure, but I think this should work:

sqlStr = "SELECT * FROM dbo_LaserMachineMaintLog WHERE [LaserMachine] = " &
Me.cboLaserMachine & " AND [Hours] = '" & Me.cboHours & "';"

Set rs = db.OpenRecordset(sqlStr, dbOpenDynaset, dbSeeChanges)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top