Ok, I got it working. But I had to manipulate the codes to fit my
preferences.
instead of having two buttons I only have one. And I do not have a list
box
to make a selection for filtering.
My button first generates the number and automatically populates the
report.
However It does not filter for the highest batch number. Here is my codes.
I suspect an error in this line. (strWhere = varBatchID). Not sure if I
have
it right.
Option Compare Database
Option Explicit
Private Sub PrintManifest_Click()
'On Error GoTo Err_Handler
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSql As String
Dim lngBatchID As Long
Dim lngKt As Long
Dim varBatchID As Variant
Dim strWhere As String
Const strcDoc = "Manifest"
'Create the new batch, and get the number.
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblBatch", dbOpenDynaset, dbAppendOnly)
rs.AddNew
rs!DateTime = Now()
lngBatchID = rs!BatchID
rs.Update
rs.Close
'Give this batch number to all members who have not been printed.
strSql = "UPDATE Tracking SET BatchID = " & lngBatchID & " WHERE
BatchID
Is Null;"
db.Execute strSql, dbFailOnError
lngKt = db.RecordsAffected
'select the highest batch
varBatchID = DMax("BatchID", "tblBatch")
'if the report is already open. close it.
If CurrentProject.AllReports(strcDoc).IsLoaded Then
DoCmd.Close acReport, strcDoc
End If
'Open it filtered for the highest batch number
strWhere = varBatchID
DoCmd.OpenReport strcDoc, acViewPreview, , strWhere
Exit_Handler:
Set rs = Nothing
Set db = Nothing
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation,
"PrintManifest_Click()"
Resume Exit_Handler
End Sub
Allen said:
Just downloaded it again and tested in Access 2003. Works fine.
Press Ctrl+G and choose Compile on the Debug menu (in the code window.)
Or you may have a problem with references:
http://allenbrowne.com/ser-38.html
Or you may need to start Access with an administrative shortcut
(particularly if using Windows Vista):
http://allenbrowne.com/bug-17.html#RunAsAdmin
I tried this and it did not work. Even the sample database that I
downloaded
[quoted text clipped - 17 lines]
manifest number and print it.
Is this doable??