• Linking a button to a form

    Author
    Topic
    #457894

    I have command button that brings up a report. How do I create a link so it will only bring up the report tied to the customer on the form? At first I created a perimeter query but that could drive everyone crazy.

    cmdViewQuote
    Control Source: QuoteGroup

    Viewing 3 reply threads
    Author
    Replies
    • #1149460

      I have command button that brings up a report. How do I create a link so it will only bring up the report tied to the customer on the form?

      You should have a customer ID or Number. Or any field that is unique for each record.
      Lets say that you name this field CustomerNumber. Put that field on your form and on your report. You can set the Visible property to No if you want.
      Under the click event of the button, use the following instruction :
      DoCmd.OpenReport “ReportName”, acNormal, , “CustomerNumber = ” & Forms!YourFormName!CustomerNumber

    • #1149564

      I’m afraid I’ve made a mess of this. I’ve made several format errors that if I fix now will require adjusting a lot of queries and links on forms.

      The primary key for the form is Quote Group while the primary key on the report has no space, QuoteGroup. I’ll correct it if need be but first I would like to see if that is the only thing that I have wrong.

      Private Sub cmdViewQuote_Click()

      DoCmd.OpenReport “rptQuote”, acNormal, , “Quote Group = ” & Forms!frmProdSelect_QuoteManager!QuoteGroup

      End Sub

      • #1149566

        What is the type of Quote Group ? Is it Numeric or Text ?

        For Numeric it’s OK.

        Code:
        DoCmd.OpenReport "rptQuote", acNormal, , "[Quote Group] = " & Forms!frmProdSelect_QuoteManager!QuoteGroup

        If it is Text you should use :

        Code:
        DoCmd.OpenReport "rptQuote", acNormal, , "[Quote Group] = '" & Forms!frmProdSelect_QuoteManager!QuoteGroup & "'"
      • #1149568

        DoCmd.OpenReport “rptQuote”, acNormal, , “Quote Group = ” & Forms!frmProdSelect_QuoteManager!QuoteGroup

        If a field name contains a space, you should enclose the name in square brackets.
        What data type is “Quote Group” ? Is it a Number or Text?
        if a Number, you need:
        [indent]DoCmd.OpenReport “rptQuote”, acNormal, , “[Quote Group] = ” & Forms!frmProdSelect_QuoteManager!QuoteGroup[/indent]

        If it is Text
        [indent]DoCmd.OpenReport “rptQuote”, acNormal, , “[Quote Group] = ” & chr(34) & Forms!frmProdSelect_QuoteManager!QuoteGroup & chr(34)[/indent]
        Chr(34) is just code for “, so this just puts double quotes around the form value.

        • #1149569

          If a field name contains a space, you should enclose the name in square brackets.

          Oops I forgot the square brackets. Thanks John.

    • #1149576

      It was text and that worked well. Thank you.
      I didn’t realize that it was going to automatically print it out though. Unless there’s another way around it, I’ve put together a macro to open it in print preview. Will you please tell me how to add that into the module. The macro name is mViewQuote.

      I tried this but it didn’t work:

      Private Sub cmdViewQuote_Click()

      DoCmd.RunMacro “mViewQuote”, acNormal, , “QuoteGroup = ‘” & Forms!frmProdSelect_QuoteManager![QuoteGroup] & “‘”

      End Sub

      • #1149577

        You don’t need a macro to do that. Just replace acNormal by acPreview.

        Code:
        DoCmd.OpenReport "rptQuote", acPreview, , "QuoteGroup = '" & Forms!frmProdSelect_QuoteManager!QuoteGroup & "'"
    • #1149580

      I can’t thank you enough!!!

    Viewing 3 reply threads
    Reply To: Linking a button to a form

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: