Results 1 to 6 of 6
  1. #1
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    101

    Populating a textbox if another contains a word on report load

    Hello there,

    I have a dynamic report that works as a sale checklist, so I have the order items listed correctly, the thing is that i have a textbox that for certain items it has to show another sub item the goes with the purchase listed, e.g: A salad will show "Dressing" below to have the employee make sure that the dressing is included. this will gain complexity because it will show a different name of dressing per type of salad, etc. but the thing to solve is that I havent been able to make it work through VBA, I had success on the expression builder, but, due to the complexity of all the different types of dressings, I rather write it on VBA.
    This is what I had on the expression builder that worked fine so far, this is within the control source of the "DressingTxt" textbox :


    Code:
    =IIf([Product] Like "Salad*" Or [Product] Like "Wrap*" Or [Product] Like "Panini*","Dressing  [   ]",Null)
    In my attempts with VBA, first of all i dont know if I should write it within sub report_Current() or sub report_load(), whats the difference? anyway, this is what I have, I have placed it on both subs without success...
    Code:
    Private Sub Report_Current()
        If InStr(Product.Text, "Salad") Then
            Me.DressingTxt.Text = "Dressing"
        End If
    End Sub
    Thanks in advance for your time and suggestions

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Load event is best for dealing with field/control values. Open is better for things like setting properties on the fly. Using it to set values can raise errors because the form/report is not fully opened until the end of the event. Load event runs after Open event.

    You might want to consider setting the report control property to a function that returns the wanted value if you have many of these variations. I figure a Select Case block would be the way to go.

    EDIT - can't tell if your sample refers to the main report or sub. Your issue may just be one of improper syntax when referring to the subreport. It depends on whether or not the code is on the sub or the main.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    101
    Quote Originally Posted by Micron View Post
    Load event is best for dealing with field/control values. Open is better for things like setting properties on the fly. Using it to set values can raise errors because the form/report is not fully opened until the end of the event. Load event runs after Open event.

    You might want to consider setting the report control property to a function that returns the wanted value if you have many of these variations. I figure a Select Case block would be the way to go.

    EDIT - can't tell if your sample refers to the main report or sub. Your issue may just be one of improper syntax when referring to the subreport. It depends on whether or not the code is on the sub or the main.
    Thanks for your answer, this is a main report that pulls data from a query where the SO is filtered to show the list of items
    Code:
    SELECT SalesDetail.Product, SalesDetail.Qty, SalesDetail.Notes, Sales.Date, Sales.SO, Sales.SaleType, FROM Sales INNER JOIN SalesDetail ON Sales.SO = SalesDetail.SO WHERE (((Sales.SO)=[Forms]![POS]![SO]));

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Hard coding in VBA the associated values can get frustrating if you are continually adding items or need to change associated value which means modifying and/or expanding code. Would be best done with a related table.

    I don't use parameterized queries. I prefer VBA to construct filter criteria and apply to form or 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.

  5. #5
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    101
    Quote Originally Posted by Micron View Post
    Load event is best for dealing with field/control values. Open is better for things like setting properties on the fly. Using it to set values can raise errors because the form/report is not fully opened until the end of the event. Load event runs after Open event.

    You might want to consider setting the report control property to a function that returns the wanted value if you have many of these variations. I figure a Select Case block would be the way to go.

    EDIT - can't tell if your sample refers to the main report or sub. Your issue may just be one of improper syntax when referring to the subreport. It depends on whether or not the code is on the sub or the main.
    At the end I managed to create a sub function with the select case in it and worked just fine, thanks!

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You're welcome. Glad I could help, even if only a little bit.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Bound textbox doesn't load at OPEN/LOAD
    By GraeagleBill in forum Forms
    Replies: 6
    Last Post: 09-23-2022, 12:45 AM
  2. Replies: 37
    Last Post: 10-21-2019, 12:29 PM
  3. Populating a Textbox
    By Daisy509th in forum Access
    Replies: 1
    Last Post: 03-16-2018, 07:12 AM
  4. Replies: 3
    Last Post: 03-07-2013, 12:43 PM
  5. Load textbox from another textbox
    By siddel77 in forum Programming
    Replies: 12
    Last Post: 08-30-2011, 01:46 PM

Tags for this Thread

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