Hi Marco,
Do I need to convert my macro to VBA and add the below?
No. Leave your macro as it is for the present time.
Open your report in design view. Then click on View > Code. You should see a
module open. At the very minimum, it should include two lines of code:
Option Compare Database
Option Explicit
If you are missing the second line of code shown above, then add it
manually. Then click on Tools > Options while in the VBA Editor, select the
General tab, and place a check in "Require Variable Declaration". I also
advise clearing the check in the first option, which reads "Auto Syntax
Check". I call that the carpel-tunnel option, because it just produces an
extra error dialog anytime you have an error in the syntax of your code. It
is simply not needed, because syntax errors will cause the code to light up
red, anyways. More details here:
Always Use Option Explicit
http://www.access.qbuilt.com/html/gem_tips.html#VBEOptions
Copy the code shown below, and paste it into your new code module for the
report(s) in question. I adjusted the code slightly, so that it sets the
caption to [CustomerName], as you indicated in your initial posting. This
field must be available to the report, or else you will get a compile error.
I also added a Report_Close event procedure, which reverses the maximize
step in the activate procedure. If you always run your application maximized,
then you can delete the DoCmd.Maximize line, and skip adding the Report_Close
procedure.
Private Sub Report_Activate()
On Error GoTo ProcError
Me.Caption = Me.CustomerName
DoCmd.Maximize
ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , "Error in
Report_Activate event procedure..."
Resume ExitProc
End Sub
Private Sub Report_Close()
On Error GoTo ProcError
DoCmd.Restore
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Report_Close..."
Resume ExitProc
End Sub
After adding these two procedures, click on Debug > Compile ProjectName,
where ProjectName is the name of your VBA project (usually the same as the
name of the database, unless you specifically change it). Hopefully, your
code will compile without any errors. If you do get a compile error, try to
identify the cause and correct it. If the menu item becomes "greyed" out,
this means that your code compiled without any problems.
Tom Wickerath
Microsoft Access MVP
http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
MarcoR said:
Tom,
Thank you for your reply.
I am not at all familiar with VBA codes.
Do I need to convert my macro to VBA and add the below?
Thankyou