Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2002
    Posts
    18

    show vba variable in a form

    How can I make a textbox on a form show a "public"-variable?
    I made a code which generates de value of a variable (let's say "intTest". But now I want to show this variable on a form. I hoped that i could just refer to it by giving the name "intTest" at the properties of a textbox.

    Thanks for your time

  2. #2
    Join Date
    Nov 2002
    Location
    San Francisco
    Posts
    251

    Re: show vba variable in a form

    you can have public variable... just define it out of any sub or function with PUBLIC word

    e.g.

    PUBLIC strMyText as string

    then

    if you have a let's say text box on the form and you want to put that value into in....

    use me.txtMyText.Value = strMyText when you open the form or when you hit the button

    the ther way is to use function, which returns the value

    Public Function ReturnMyValue() As String
    ReturnMyValue = strMystring
    End Function

    and use the function as data source for that field



    jiri

  3. #3
    Join Date
    Oct 2014
    Posts
    2

    Question Passing VBA variables to a print report

    I use that exact method to pass a beginning and ending date to the report so they may be printed on the report. When I go to print preview or just print, the data variables do not show up. When I changed to code from acViewReport to acViewPreview the variables show up only on page one of the preview but do not print. There must be something I don't understand about this.

    DoCmd.OpenReport "Company Sales", acViewReport, , "[Sales]!ClosingDate BETWEEN" & StartDate & " And " & EndDate

    On the report itself I use as a control source =GetEnd() and =GetStart() functions to display the dates in text boxes on the report.

    Public Function GetStart()
    GetStart = Sdate
    Sdate = ""
    End Function

    Public Function GetEnd()
    GetEnd = EDate
    EDate = ""
    End Function

    Again, with acViewReport the variables show up in Report View but not Print; with acViewPreview they show up on the first page only but still do not print.

    I really am confused.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    12,532
    Why do you clear the value of sdate and edate after one use..... that would explain why you see them only once.

    Strictly speaking when you open the report you should format and delimt you date values properly.
    Delimit with #
    Format as ISO yyyy mm dd, or US MM mm dd yyyy

    There should be a space after each word, in this case after the between
    Code:
     ...between #" & format(startdate, "yyyy mm dd") & "# and #"......

    Assuming sdate is your global variable in your report assign the value of sdate to whatever control formatted as required, if required.
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Oct 2014
    Posts
    2

    Thumbs up

    Quote Originally Posted by healdem View Post
    Why do you clear the value of sdate and edate after one use..... that would explain why you see them only once.

    Strictly speaking when you open the report you should format and delimt you date values properly.
    Delimit with #
    Format as ISO yyyy mm dd, or US MM mm dd yyyy

    There should be a space after each word, in this case after the between
    Code:
     ...between #" & format(startdate, "yyyy mm dd") & "# and #"......

    Assuming sdate is your global variable in your report assign the value of sdate to whatever control formatted as required, if required.
    Before I enter the select sequence to pick a report, both SDate and EDate are manipulated -
    Sdate = Replace(StartDate, "#", "")
    EDate = Replace(EndDate, "#", "")
    Select Case ReportValue

    At the moment I don't know why I was clearing them but I'm sure it will surface at some point. In the mean time, removing the clear steps fixed the problem Thank you for your help.

Posting Permissions

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