Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Code help! 1

Status
Not open for further replies.

akash2010

MIS
Joined
Nov 29, 2010
Messages
4
Location
US
Hello,

I have form where a user can choose criteria (PeopleSoft, ClickCommerce or InfoEd) and run a report (three different reports pertaining to what has been selected). So basically, I want it to run a specific report, when an option is chosen.

Below is the VB code i wrote (yeah, I know its full of errors, I am VERY new to Access). It doesn't seem to be doing anything :(

Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocPeopleSoft = "RPT_EC_COMPARE"
stDocClickCommerce = "RPT_CC_COMPARISON"
stDocInfoEd = "RPT_IE_COMPARISON"


'Vendor Criteria
If Me!Combo15 = "PeopleSoft" Then
stLinkCriteria = stLinkCriteria & "[VENDOR]='" & Me!Combo15 & "'"
DoCmd.OpenReport stDocPeopleSoft, acViewReport, , stLinkCriteria
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF

ElseIf Me!Combo15 = "ClickCommerce" Then
stLinkCriteria = stLinkCriteria & "[VENDOR]='" & Me!Combo15 & "'"
DoCmd.OpenReport stDocClickCommerce, acViewReport, , stLinkCriteria
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF
: stLinkCriteria = stLinkCriteria & "[VENDOR] Like" & " '*' "

ElseIf Me!Combo15 = "InfoEd" Then
stLinkCriteria = stLinkCriteria & "[VENDOR]='" & Me!Combo15 & "'"
DoCmd.OpenReport stDocInfoEd, acViewReport, , stLinkCriteria
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF

End If

PLEASE HELP!!! I appreciate your time and patience!!!
 
I would change the combo box names and then use code like:
Code:
    Dim stDocName As String
    Dim stLinkCriteria As String
    
    stDocPeopleSoft = "RPT_EC_COMPARE"
    stDocClickCommerce = "RPT_CC_COMPARISON"
    stDocInfoEd = "RPT_IE_COMPARISON"
    strLinkCriteria = "1=1 "
    'change the name of Combo15 to cboReport
    Select Case Me.cboReport
      Case "PeopleSoft"
        stDocName = stDocPeopleSoft
      Case "ClickCommerce"
        stDocName = stDocClickCommerce 
      Case "InfoEd"
        stDocName = stDocInfoEd 
    End Select
    'Vendor Criteria
    'change the name of Combo15 to cboVendor
    If Not IsNull(Me.cboVendor) Then
      stLinkCriteria = stLinkCriteria & " AND [VENDOR]='" & Me!cboVendor & "'"
    End If

    DoCmd.OpenReport stDocName, acViewReport, , stLinkCriteria
    DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF

Duane
Hook'D on Access
MS Access MVP
 
OMG! Thank you thank you thank you, thank you!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top