Error traps, code residue & lanscape mode

J

Jim

I recently had an exchange via this site, which generated
excellent advice, as follows:

Subject: Re: Opening report from form
From: "Allen Browne" <[email protected]>
Sent: 5/21/2004 11:12:57 PM

Use the WhereCondition of the OpenReport action to limit
the report to the
current record in the form.

This example assumes the form has a numeric field
named "ID" that uniquely
identifies the record to print. Use the code in the Event
Procedure for the
Click event of a command button named "cmdPrint".

Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.Dirty Then 'Save first
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to
print
MsgBox "Pick a record."
Else
strWhere = "[ID] = " & Me.ID
DoCmd.OpenReport "MyReport", acViewPreview, ,
strWhere
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org."

I have a few houskeeping type follow-up questions:

1. My VBA knowledge is weak. When I use the Access
command button wizard to create an "open report" button,
rather than the method set out above, the VB inlcudes
code as follows:
"Private Sub Open_Opening_Reports_Click()
On Error GoTo Err_Open_Opening_Reports_Click

Dim stDocName As String

stDocName = "OpenOpeningReports"
DoCmd.RunMacro stDocName

Exit_Open_Opening_Reports_Click:
Exit Sub

Err_Open_Opening_Reports_Click:
MsgBox Err.Description
Resume Exit_Open_Opening_Reports_Click

End Sub"

Should I be including language, such as that set out
above, regarding errors, or is the current language,
which works great, sufficient? (I'm leaning toward "if it
ain't broke . . . ")

2. After fumbling around with the command buttons for a
while, and deleting a number of failed attempts, I find
there is a fair amount of code residue, no longer related
to any button behind my forms--I realize this might seem
like a silly question-Should I delete this code or let it
be?

3. Finally, and I apologize for going outside this
forum's heading: I have some reports that are
sufficiently wide that they need to be viewed and printed
in landscape mode. For some reason, even after I save
them in that mode, they revert to portrait mode from time
to time--any idea why that is and how I can prevent it?

Thank you in advance.

Jim
 
E

Eric Cárdenas [MSFT]

I have a few houskeeping type follow-up questions:
1. My VBA knowledge is weak. When I use the Access
command button wizard to create an "open report" button,
rather than the method set out above, the VB inlcudes
code as follows:
"Private Sub Open_Opening_Reports_Click()
On Error GoTo Err_Open_Opening_Reports_Click

Dim stDocName As String

stDocName = "OpenOpeningReports"
DoCmd.RunMacro stDocName

Exit_Open_Opening_Reports_Click:
Exit Sub

Err_Open_Opening_Reports_Click:
MsgBox Err.Description
Resume Exit_Open_Opening_Reports_Click

End Sub"

Should I be including language, such as that set out
above, regarding errors, or is the current language,
which works great, sufficient? (I'm leaning toward "if it
ain't broke . . . ")

2. After fumbling around with the command buttons for a
while, and deleting a number of failed attempts, I find
there is a fair amount of code residue, no longer related
to any button behind my forms--I realize this might seem
like a silly question-Should I delete this code or let it
be?
--------------------
Because VBA is an interpreted language, the less code there is the more
efficient it will be. However there is also the issue of lack of
experience. I would leave code as long as they work to your satisfaction.
Later on, when you gain experience, you can examine it and fine tune it.

Hope this helps,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top