Results 1 to 10 of 10
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    code fragment

    I entered the flowing VBA Access 2010 code in the code (Alt-F11) window of my Access 2010 application.

    Code:
    Option Compare Database
    Option Explicit
    
     'Create a String varaibale named NewValList
     Dim NewValList As String
     
     'Build NewValList string in chunks.
     
    NewValList = Chr(34) + "First item" + Chr(34) + ";"
    NewValList = NewValList + Chr(34) + "Second Item" + Chr(34) + ";"
    NewValList = NewValList + Chr(34) + "Third Item" + Chr(34) + ";"
    NewValList = NewValList + Chr(34) + "Fourth Item" + Chr(34)
    'At this point . NewValList contains...
    '"First item": "Second Item" + "Third Item"" "fourth Item"
    'Make new string the Row Source for value list named OpsCombo
    Me!OpsCombo.RowSourceType = "Value List"
    Me!OpsCombo.RowSource = NewValueList
    'Set the selection to first item in drop down menu
    Me!OpsCombo.Value = Me!OpsCombo.ItemData(0)
    Now how do I run it? I can cut and paste it to any window I want. I guess that I should


    make a subprogram out of it with Start Sub and End Sub put around it. Anyway, I got this from a tutorial and I believe it is
    good with no errors. But how do I run it?

    Respectfully,


    Lou_Reed

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You could include it in the code for the appropriate event (when you want the row source set to this). That could be a button, the form's open event, etc. With the combo reference, it is form-specific.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, I see your point but I just want to play with this code - do some things to it.

    I have already got a db selected. I am going to use the code on that. But, how?

    It is a code fragment.

    That is my question.


    Respectfully,


    Lou_Reed

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Simplest is probably behind a button. You can make it a public sub/function, but I don't see the point.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If your question was how to get it behind a button:

    http://www.baldyweb.com/FirstVBA.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    The code is meant to run behind a form, being the value list row source for a combo box on that form. Google access combobox for more info.

  7. #7
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    The point is just to learn about the VBA code system. A code fragment was used in a tutorial and I want
    to use it and work with it. It is not a project.

    Respectfully,


    Lou_Reed
    '

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Did you get it working?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Not Yet. I am trying however.

    Respectfully,

    Lou_Reed

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Post back if you get stuck. I didn't know if posts 4 & 5 got lost in the confusion.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Keyword or fragment search
    By orange in forum Sample Databases
    Replies: 0
    Last Post: 01-23-2015, 02:47 PM
  2. Replies: 1
    Last Post: 05-04-2013, 12:19 PM
  3. Replies: 3
    Last Post: 06-20-2011, 05:36 PM
  4. adapt the given fragment code
    By jumpingtree in forum Queries
    Replies: 2
    Last Post: 09-06-2010, 08:54 PM
  5. Adapting a fragment code
    By accesscurrymoodle in forum Programming
    Replies: 1
    Last Post: 08-23-2010, 08:28 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