Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    daSpud is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    17
    Thanks for the info on visibility. I found that Me.Lot_No works just fine to test and in the msgbox statement. 1 more hurdle passed.



    I want to be able to construct my own address line (these are labels). Currently the label is as follows: https://www.screencast.com/t/mhes0me3929

    The top line prints the data from the table and the other lines are prompted as parameters and I just ignore them in my testing, but now I have enough info to get serious about specifying my own strings to go there (thanks to your help). The table contains various address information and I need to parse it out depending on the content of some of the other table fields. The current application has a whole bunch of logic crammed into one of the tiny boxes on the query they are using. I am trying to move the whole thing to VBA so I need to know how to define strings that I can put on the label/report and fill with data in VBA.

  2. #17
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    How would you want to 'fill with data in VBA'? Can't directly set Value property of textbox on report.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #18
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'll get out of the way, though you can set the value of a textbox on a report with VBA. It would look similar to what I said for a textbox control source:

    Me.TextboxName ="Dear " & [FirstName] & ", thank you for blah"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #19
    daSpud is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    17
    Yep, I can't do it directly to the textbox.

    In other systems I can put a variable name on a report detail section and it prints whatever is in that variable at the time for formatting. I had hoped that Access had something similar so I can look at the table entry and format what I want to appear on the label.

    I want to put something on the report that says "use the current value of this when you format the line". And I will have given this the text I want to be there. It works for fields in the table and I was hoping for a field somewhere not in the table that I could manipulate with VBA. Maybe I can't do this in Access?

  5. #20
    daSpud is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    17
    Quote Originally Posted by pbaldy View Post
    I'll get out of the way, though you can set the value of a textbox on a report with VBA. It would look similar to what I said for a textbox control source:

    Me.TextboxName ="Dear " & [FirstName] & ", thank you for blah"
    This is exactly what I wanted and it works! THANK YOU

  6. #21
    daSpud is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    17
    Quote Originally Posted by June7 View Post
    ...Can't directly set Value property of textbox on report.
    Me.Text8.value = "blah blah" worked perfectly. It also works without the .value

    When I originally tried it the textbox was bound to =Trim[name] and when I put an unbound textbox on the report I could assign the value I wanted.

  7. #22
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    Well, dang! I could have sworn I have gotten "Cannot set value after report open is initialized" (or similar wording) error message in past when trying to set Value property of textbox on report with VBA so I quit trying. Wish I could remember circumstances that led me down that path.


    Yes, Value is default property of data controls.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #23
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by daSpud View Post
    This is exactly what I wanted and it works! THANK YOU
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #24
    daSpud is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    17
    To answer the question of why I want to do things in VBA, I found this:

    Code:
    Temp_Address_1: IIf(DatePart("m",Now())=1 And [Here_Jan]="Y" Or DatePart("m",Now())=2 And [Here_Feb]="Y" Or DatePart("m",Now())=3 And [Here_Mar]="Y" Or DatePart("m",Now())=4 And [Here_Apr]="Y" Or DatePart("m",Now())=5 And [Here_May]="Y" Or DatePart("m",Now())=6 And [Here_Jun]="Y" Or DatePart("m",Now())=7 And [Here_Jul]="Y" Or DatePart("m",Now())=8 And [Here_Aug]="Y" Or DatePart("m",Now())=9 And [Here_Sep]="Y" Or DatePart("m",Now())=10 And [Here_Oct]="Y" Or DatePart("m",Now())=11 And [Here_Nov]="Y" Or DatePart("m",Now())=12 And [Here_Dec]="Y",Null,[Second_Address_Line_1])
    for each of the fields Address1, address2, city, state, zip and country. In VBA I can set the current month number and make the test of the "here" fields one time and construct the proper address. Part of this problem is poor database design, but I cannot do anything about that.

  10. #25
    daSpud is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    17
    Setback -- the Me.fieldname only works for fields ACTUALLY on the report layout. Even though the the field name prompt window comes up when you type "Me." and it has all the record source table names in it you get a not found error when it runs.

    When I discovered that Me.Lot_No worked Lot_No was a field in the report detail section. Once I took it out and put in the text boxes I wanted to format, I lost the ability to reference it.

    Is there some kind of a BIND statement that lets me reference all the fields in a table in VBA?

  11. #26
    daSpud is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    17
    Got around it by defining text boxes with all the needed fields concatenated and put on the report 0 high. Would still like to know if there is an easier way.

  12. #27
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,973
    The "Me.ControlName' notation is for controls on the currently used object whether it's a form or report.

    So the control does need to be on the form/report though it can be shrunk as you've done or hidden by setting visible=false

    Alternative methods include using public variables or tempvars.
    It's largely a matter of personal preference
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 08-11-2018, 11:22 AM
  2. Replies: 4
    Last Post: 04-30-2014, 09:40 PM
  3. Replies: 1
    Last Post: 07-25-2013, 01:20 PM
  4. Replies: 2
    Last Post: 05-10-2013, 03:37 PM
  5. How to Filter Report
    By mikel in forum Reports
    Replies: 2
    Last Post: 08-28-2009, 10:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums