designation of report used with control variable ('er something)

M

magmike

What I am trying to do, is create multiple reports (or I should say,
prefabbed letters). Then, using a dropdown box on a "SendLetters"
form, allow the user to select the desired letter to send, click a
button, and then the corresponding "letter" or report open with the
records data where it should be, on the report or letter that was
selected in the "letter" or report drop down box.

Is this making any sense?

Thanks in advance for your help!

magmike
 
G

Guest

Hi
Not too complicated. You will need to use some VBA to select the report.
Suggest you first create a table with the something like the following
tblLetters
LetterNo - Autonumber - Primary Key
LetterName - Text
ReportName - Text
SeqNo - Integer

Create a combo e.g. (cmbLetter) that displays the LetterName and sort it in
SeqNo. This allows you to create your own sort sequence. Put the most
common ones at the top.

In the VBA for the button onClick event, you can use something like this. I
prefer to use a sub in a generic module to open reports. Saves creating
error trapping etc.

Private Sub Report_Button_Click()
dim strReportName as String

strReportName = Forms!frmReportSelector!cmbLetter

' DoCmd.RunCommand acCmdSaveRecord ' Save the record. Not needed if the
button is not on the form you use to enter data

subOpenReports strReportName
End Sub

Put this in a module. I have one called modGeneric where I have lots of
these generic functions and subs.

Public Sub subOpenReports(strReportName As String, Optional strQuery As
String, Optional strWhere As String, Optional strOpenArgs As String)
' This function is used in the Click event of command buttons that opens
reports

On Error GoTo Error_subOpenReports

' Open specified form.
DoCmd.OpenReport strReportName, acPreview, strQuery, strWhere

Exit_subOpenReports:
On Error GoTo 0
Exit Sub

Error_subOpenReports:

MsgBox "An unexpected situation arose in your program." & funCrLf & _
"Please write down the following details:" & funCrLf & funCrLf & _
"Module Name: modGeneric" & funCrLf & _
"Type: Module" & funCrLf & _
"Calling Procedure: subOpenReports" & funCrLf & _
"Error Number: " & Err.Number & funCrLf & _
"Error Descritption: " & Err.Description

Resume Exit_subOpenReports

End Sub
 

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