G
Guest
Hi. I'm trying to learn VBA by the seat of my pants - like any good
programmer would - and need some help. I'm trying to run a query/report based
on a week ending date that the user enters from a form [which is a combo box
from a select distinct WeekEnding date from table] I am assuming that I need
to create a recordset in order to get a subset of the table. I copied the
code from another working module - like any good programmer would - and
modified it to suit my needs. But the recordset does not return any records,
even though they are definately in the table, and I have debugged the
criteria (txtWeekEnding). It stops at the line rst.MoveLast and displays the
message box from error 3021. Am I correct in assuming that this code is all I
need to get the subset of records? Here is the code:
Public Sub RecordsetUpdate()
On Error GoTo ErrorHandler
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tblTaggingProduction WHERE
tblTaggingProduction.WeekEnding = " & txtWeekEnding)
rst.MoveLast
rst.MoveFirst
txtResult = "Criteria returns " & rst.RecordCount & " records"
Exit Sub
ErrorHandler:
If Err.Number = 3021 Then
MsgBox "No items match the specified criteria. Data fields " _
& "will now be reset. Please change your criteria and " _
& "and try again.", vbOKOnly, "No data"
Call FormSetup
Else
MsgBox "Error in the Recordset Update Module having number " _
& Err.Number & " and the description: " & Err.Description _
, vbOKOnly, "Unexpected Error"
End If
End Sub
Thank you for any help offered...
programmer would - and need some help. I'm trying to run a query/report based
on a week ending date that the user enters from a form [which is a combo box
from a select distinct WeekEnding date from table] I am assuming that I need
to create a recordset in order to get a subset of the table. I copied the
code from another working module - like any good programmer would - and
modified it to suit my needs. But the recordset does not return any records,
even though they are definately in the table, and I have debugged the
criteria (txtWeekEnding). It stops at the line rst.MoveLast and displays the
message box from error 3021. Am I correct in assuming that this code is all I
need to get the subset of records? Here is the code:
Public Sub RecordsetUpdate()
On Error GoTo ErrorHandler
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tblTaggingProduction WHERE
tblTaggingProduction.WeekEnding = " & txtWeekEnding)
rst.MoveLast
rst.MoveFirst
txtResult = "Criteria returns " & rst.RecordCount & " records"
Exit Sub
ErrorHandler:
If Err.Number = 3021 Then
MsgBox "No items match the specified criteria. Data fields " _
& "will now be reset. Please change your criteria and " _
& "and try again.", vbOKOnly, "No data"
Call FormSetup
Else
MsgBox "Error in the Recordset Update Module having number " _
& Err.Number & " and the description: " & Err.Description _
, vbOKOnly, "Unexpected Error"
End If
End Sub
Thank you for any help offered...