Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2003
    Location
    NJ, USA
    Posts
    8

    Angry Unanswered: Global string storage and call

    I am looking for a little help with global modules declartion and call up.

    I am used to VB6 and are new to Access 2000. in VB if I wanted to run multipal reports with the same date range I could declair global strings and then call them and print them with the same wording on multipal reports.

    For example. I would place in coding if in november and I run sales tax report the function would calculate automatically that I am looking for Octobers by setting 2 global strings dbeginst & dendst to 10/01/2003 and 10/31/2003 and inject them into a between statement and then run the report thru the query and inject the header "Sales Tax Report for " + dbeginst + " to " + dendst, and print on the report.

    The only way I have been able to do this function correctly is to create 2 text boxes and call them in from a form after setting them and to then go back and recall the text boxes by putting a label on the report then a text box for the begin date and then a label for the to and then another text box.

    this seems a little extreme when i can do this all with code in VB6 but the report gives me errors if i don't do it in the later way.

    Could some body shed some light on what I am missing here. I know access works different, but I must be doing something wrong?

  2. #2
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: Global string storage and call

    Originally posted by tbz
    I am looking for a little help with global modules declartion and call up.

    I am used to VB6 and are new to Access 2000. in VB if I wanted to run multipal reports with the same date range I could declair global strings and then call them and print them with the same wording on multipal reports.

    For example. I would place in coding if in november and I run sales tax report the function would calculate automatically that I am looking for Octobers by setting 2 global strings dbeginst & dendst to 10/01/2003 and 10/31/2003 and inject them into a between statement and then run the report thru the query and inject the header "Sales Tax Report for " + dbeginst + " to " + dendst, and print on the report.

    The only way I have been able to do this function correctly is to create 2 text boxes and call them in from a form after setting them and to then go back and recall the text boxes by putting a label on the report then a text box for the begin date and then a label for the to and then another text box.

    this seems a little extreme when i can do this all with code in VB6 but the report gives me errors if i don't do it in the later way.

    Could some body shed some light on what I am missing here. I know access works different, but I must be doing something wrong?
    It should not be that much different. I use standard modules quite frequently to submit data to reports and to perform calculations within queries. Declare a Public Function in a standard module and you can then use it anywhere within Access.

    Hope this helps.

    Gregg

  3. #3
    Join Date
    Oct 2003
    Posts
    706

    Lightbulb

    You need to make sure (a) that the variable being used to store the value is global; and (b) that you write a function that returns the value. Other parts of Access cannot directly reach VBA variable-values, but they can see public functions... which can be used to expose them.
    ChimneySweep(R): fast, automatic
    table repair at a click of the
    mouse! http://www.sundialservices.com

  4. #4
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238

    Re: Global string storage and call

    Originally posted by tbz
    I am looking for a little help with global modules declartion and call up.

    I am used to VB6 and are new to Access 2000. in VB if I wanted to run multipal reports with the same date range I could declair global strings and then call them and print them with the same wording on multipal reports.

    For example. I would place in coding if in november and I run sales tax report the function would calculate automatically that I am looking for Octobers by setting 2 global strings dbeginst & dendst to 10/01/2003 and 10/31/2003 and inject them into a between statement and then run the report thru the query and inject the header "Sales Tax Report for " + dbeginst + " to " + dendst, and print on the report.

    The only way I have been able to do this function correctly is to create 2 text boxes and call them in from a form after setting them and to then go back and recall the text boxes by putting a label on the report then a text box for the begin date and then a label for the to and then another text box.

    this seems a little extreme when i can do this all with code in VB6 but the report gives me errors if i don't do it in the later way.

    Could some body shed some light on what I am missing here. I know access works different, but I must be doing something wrong?
    You could use the OpenArgs option of the Docmd.OpenReport command to pass variables into a report. You can only change the report layout in the Report Open event. You could use code such as:

    ' Put this any where in your code that will call the report
    DoCmd.OpenReport ReportName:="MyReport", View:=acPreview, WhereCondition:="Between #" & dbeginst "# And #" & dendst & "#", OpenArgs:="Sales Tax Report For " + dbeginst + " to " + dendst

    ' Put this in your report
    Private Sub Report_Open(Cancel As Integer)
    If Len(Me.OpenArgs) Then _
    Me("lblReportTitle").Caption = Me.OpenArgs
    End Sub

  5. #5
    Join Date
    Nov 2003
    Location
    NJ, USA
    Posts
    8

    Thanks everyone

    I did not know you have to declare a public.

    And thanks for the line of code it worked great.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •