T
Tom
Hi
I am still a newbie to VBA, and have a problem with the code below.
The theory is as follows.
This code is called when a button is clicked on a continuous form. The
detail area of the form shows user names that can have an ID card printed.
They are selected using a check box hidden behind a button. When the print
button is pressed, it should select all of the users with status 'N' (new),
output their information to a form to print the barcoded cards, then open
the underlying data table in which it will change the cards' status from
'N'(ew) to 'P'(rinted), and load the PC name, the Administrator's ID and the
Date/Time into their appropriate fields.
You can see there are two major parts to this code: print the cards, and
update the table.
I have tried running the report followed by updating the table, and vice
versa, and both methods give problems.
If I run the report then update the table, the report runs OK, and the table
updates OK, but on leaving the code and returning to the underlying form,
the form's display is corrupt (like it could not get the lines out in time).
Even exiting the form to its parent form and coming back in again results in
a corruption of the form.
If I update the table then run the report, the update goes OK but the report
shows no data.
In order to try and debug it, I have embedded MsgBoxes to display the
selection data being passed on both the record select for the table update
and the record select on the report (using the 'In()' command). Both
MsgBoxes suggest there is no problem at all. This is most weird when the
report is being run after the table update as it clearly tells me the report
is being passed the correct data (eg "REC_ID in(101,102,103)).
Can anyone help me with this? This is my first attempt at serious code and
it is slow going ;-)
Regards
Tom
==================================================
Private Sub butPrintCard_Click()
''' Firstly, set up variables as required
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim wrtSTATUS As String
Dim wrtPRINT_PC_NAME As String
Dim wrtPRINT_CARD_DATE As Date
Dim wrtPRINT_ADMIN_ID As String
Dim i As Integer
Dim strWhere As String
''' Part 1: Identify the check boxes that are checked
strWhere = MySelected
If strWhere <> "" Then
strWhere = "REC_ID in (" & strWhere & ")"
End If
'''Temporary MsgBox to prove content
MsgBox ("Check Boxes " & strWhere)
''' Open the database and table and find the records
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT * FROM OPERATOR_CARDS WHERE " &
strWhere & "ORDER BY [REC_ID]")
''' Populate variables to be written to the table
wrtSTATUS = "P"
wrtPRINT_PC_NAME = Me.PC_NAME
wrtPRINT_CARD_DATE = Now()
wrtPRINT_ADMIN_ID = Me.ADMINISTRATOR_ID
''' Move to the start of the table
rs.MoveLast
rs.MoveFirst
With rs
Do While Not .EOF
.Edit
''' Set KEY_ID to required value, carry out the update and
move to next record
.Fields("STATUS").Value = wrtSTATUS
.Fields("PRINT_PC_NAME").Value = wrtPRINT_PC_NAME
.Fields("PRINT_CARD_DATE").Value = wrtPRINT_CARD_DATE
.Fields("PRINT_ADMIN_ID").Value = wrtPRINT_ADMIN_ID
.Update
.MoveNext
Loop
End With
''' clear down db and rs, and set form to requery its underlying query, then
end the sub
Set db = Nothing
Set rs = Nothing
''' Part 2: Print the cards
'''Temporary MsgBox to prove content
MsgBox ("Print Record IDs " & strWhere)
DoCmd.OpenReport "rptPRINT_EMPLOYEE_CARDS", acViewPreview, , strWhere
DoCmd.RunCommand acCmdZoom100
Me.Requery
End Sub
===========================================================
I am still a newbie to VBA, and have a problem with the code below.
The theory is as follows.
This code is called when a button is clicked on a continuous form. The
detail area of the form shows user names that can have an ID card printed.
They are selected using a check box hidden behind a button. When the print
button is pressed, it should select all of the users with status 'N' (new),
output their information to a form to print the barcoded cards, then open
the underlying data table in which it will change the cards' status from
'N'(ew) to 'P'(rinted), and load the PC name, the Administrator's ID and the
Date/Time into their appropriate fields.
You can see there are two major parts to this code: print the cards, and
update the table.
I have tried running the report followed by updating the table, and vice
versa, and both methods give problems.
If I run the report then update the table, the report runs OK, and the table
updates OK, but on leaving the code and returning to the underlying form,
the form's display is corrupt (like it could not get the lines out in time).
Even exiting the form to its parent form and coming back in again results in
a corruption of the form.
If I update the table then run the report, the update goes OK but the report
shows no data.
In order to try and debug it, I have embedded MsgBoxes to display the
selection data being passed on both the record select for the table update
and the record select on the report (using the 'In()' command). Both
MsgBoxes suggest there is no problem at all. This is most weird when the
report is being run after the table update as it clearly tells me the report
is being passed the correct data (eg "REC_ID in(101,102,103)).
Can anyone help me with this? This is my first attempt at serious code and
it is slow going ;-)
Regards
Tom
==================================================
Private Sub butPrintCard_Click()
''' Firstly, set up variables as required
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim wrtSTATUS As String
Dim wrtPRINT_PC_NAME As String
Dim wrtPRINT_CARD_DATE As Date
Dim wrtPRINT_ADMIN_ID As String
Dim i As Integer
Dim strWhere As String
''' Part 1: Identify the check boxes that are checked
strWhere = MySelected
If strWhere <> "" Then
strWhere = "REC_ID in (" & strWhere & ")"
End If
'''Temporary MsgBox to prove content
MsgBox ("Check Boxes " & strWhere)
''' Open the database and table and find the records
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT * FROM OPERATOR_CARDS WHERE " &
strWhere & "ORDER BY [REC_ID]")
''' Populate variables to be written to the table
wrtSTATUS = "P"
wrtPRINT_PC_NAME = Me.PC_NAME
wrtPRINT_CARD_DATE = Now()
wrtPRINT_ADMIN_ID = Me.ADMINISTRATOR_ID
''' Move to the start of the table
rs.MoveLast
rs.MoveFirst
With rs
Do While Not .EOF
.Edit
''' Set KEY_ID to required value, carry out the update and
move to next record
.Fields("STATUS").Value = wrtSTATUS
.Fields("PRINT_PC_NAME").Value = wrtPRINT_PC_NAME
.Fields("PRINT_CARD_DATE").Value = wrtPRINT_CARD_DATE
.Fields("PRINT_ADMIN_ID").Value = wrtPRINT_ADMIN_ID
.Update
.MoveNext
Loop
End With
''' clear down db and rs, and set form to requery its underlying query, then
end the sub
Set db = Nothing
Set rs = Nothing
''' Part 2: Print the cards
'''Temporary MsgBox to prove content
MsgBox ("Print Record IDs " & strWhere)
DoCmd.OpenReport "rptPRINT_EMPLOYEE_CARDS", acViewPreview, , strWhere
DoCmd.RunCommand acCmdZoom100
Me.Requery
End Sub
===========================================================