I operate a database which is used for recording the inspection of instrumentation on a chemical plant. The printing of inspection sheets and the results can involve hundreds of records and is an ideal candidate for automation. I decided to give it a go.
Generated a much reduced and simplified test database. Recorded a macro to form a base, converted it to VBA - this is shown below - and then set out to make it print a single record prior to embarking on a loop addition to print a complete query contents.
Didn't get to square one. No matter what I tried I could not get anything other than a print of all records.
The original, untouched module is as follows:
----------------------------------------------------------------------------------------------------------------------------------------------------------
Option Compare Database
'------------------------------------------------------------
' Print_first_record
'
'------------------------------------------------------------
Function Print_first_record()
'DoCmd.OpenTable "Instr", acNormal, acEdit (commented out as unnecessary)
DoCmd.OpenQuery "Test_Haz_area_instr_list_rep_limited_q", acNormal, acEdit
DoCmd.GoToRecord acQuery, "Test_Haz_area_instr_list_rep_limited_q", acFirst
DoCmd.OpenReport "Test_Insp_sht_instrument_d_rep", acPreview, "", ""
End Function
----------------------------------------------------------------------------------------------------------------------------------------------------------
I would greatly appreciate it if someone could show me
a) How to modify this code to make it print the first record
and
b) How to further modify it to make it print all records in the query
Upon request I will gladly email the simplified database if this would assist.
Brian
Generated a much reduced and simplified test database. Recorded a macro to form a base, converted it to VBA - this is shown below - and then set out to make it print a single record prior to embarking on a loop addition to print a complete query contents.
Didn't get to square one. No matter what I tried I could not get anything other than a print of all records.
The original, untouched module is as follows:
----------------------------------------------------------------------------------------------------------------------------------------------------------
Option Compare Database
'------------------------------------------------------------
' Print_first_record
'
'------------------------------------------------------------
Function Print_first_record()
'DoCmd.OpenTable "Instr", acNormal, acEdit (commented out as unnecessary)
DoCmd.OpenQuery "Test_Haz_area_instr_list_rep_limited_q", acNormal, acEdit
DoCmd.GoToRecord acQuery, "Test_Haz_area_instr_list_rep_limited_q", acFirst
DoCmd.OpenReport "Test_Insp_sht_instrument_d_rep", acPreview, "", ""
End Function
----------------------------------------------------------------------------------------------------------------------------------------------------------
I would greatly appreciate it if someone could show me
a) How to modify this code to make it print the first record
and
b) How to further modify it to make it print all records in the query
Upon request I will gladly email the simplified database if this would assist.
Brian