Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Problem assigning value in Sub

Discussion in 'Information Technology' started by charles.kendricks@charter.net, Jul 28, 2006.

  1. charles.kendricks@charter.net

    Guest

    I am trying to write write a procedure for a button which will open a
    report using the value of a field in the open form as the Where
    parameter for DoCmd.Openreport. The value of the field is assigned to
    a variable defined as an Integer, and the field to which I am assigning

    the variable is an Autonumber field. But when I press the button I get
    a message box prompting me for the value of the variable. What am I
    doing wrong??? Code included below:

    Private Sub Command45_Click()
    Dim OrderNum As Integer
    OrderNum = Forms!frmClientData!frmOrderSubform!OrderNo.Value


    'Debug.Print OrderNum
    DoCmd.OpenReport "rptReceipt", acViewPreview, ,
    "[OrderNo]=OrderNum"


    On Error GoTo Err_Command45_Click


    Exit_Command45_Click:
    Exit Sub
     
  2. Loading...

    Similar Threads Forum Date
    Sikh News Sikhs Face Problems While Carrying Kirpans In Khyber-Pakhtunkhwa - SikhSiyasat.Net Breaking News Jul 29, 2016
    "Dasam" Granth - A Look At The Core Problems Dasam Granth Oct 21, 2015
    Problems In Life Sikh Sikhi Sikhism Apr 13, 2015
    How can I make decent and useful friends and from where ?? most people have a problem with me Sikh Youth Oct 23, 2013
    The Problem with Taking Too Many Vitamins Health & Nutrition Oct 18, 2013

  3. Rick Brandt

    Rick Brandt
    Expand Collapse
    Guest

    charles.kendricks@charter.net wrote:
    > I am trying to write write a procedure for a button which will open a
    > report using the value of a field in the open form as the Where
    > parameter for DoCmd.Openreport. The value of the field is assigned to
    > a variable defined as an Integer, and the field to which I am
    > assigning
    >
    > the variable is an Autonumber field. But when I press the button I get
    > a message box prompting me for the value of the variable. What am I
    > doing wrong??? Code included below:
    >
    > Private Sub Command45_Click()
    > Dim OrderNum As Integer
    > OrderNum = Forms!frmClientData!frmOrderSubform!OrderNo.Value
    >
    >
    > 'Debug.Print OrderNum
    > DoCmd.OpenReport "rptReceipt", acViewPreview, ,
    > "[OrderNo]=OrderNum"
    >
    >
    > On Error GoTo Err_Command45_Click
    >
    >
    > Exit_Command45_Click:
    > Exit Sub


    The variable name needs to be outside the quotes. Otherwise it is not
    recognized as a variable name, but rather Access assumes it must be a field in
    the Report's RecordSource. When that field name cannot be found it then treats
    it as a parameter.

    DoCmd.OpenReport "rptReceipt", acViewPreview, ,"[OrderNo]=" & OrderNum

    --
    Rick Brandt, Microsoft Access MVP
    Email (as appropriate) to...
    RBrandt at Hunter dot com
     

Share This Page