Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    marcustofeles is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2011
    Posts
    23

    Unable to populate textbox based on listbox

    Hi peeps,



    I have a listbox which get its value from a query. I also have a textbox which should simply copy the value from the listbox.
    As a newbie I have googled this extensively and found for example that me.lstbox = me.txtbox should work, but I can't get it to work. I have also come across several people mentioning Dlookup but I don't understand how that works or how to apply it.

    Help is appreciated!

    /Marcus

  2. #2
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Not sure where you put me.textbox = me. listbox, but try

    using the OnDirty event procedure.
    DLookup should also work, but it will requery the table.
    Depending on what else is going on in your form, you may have to update the textbox from another event procedure.

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Hi

    You may like to try this:

    Set the Control Source property of the text box to
    = [NameOfListBoxControl].Column(0)
    You will need to change the NameOfListBoxControl with the name of your list box control.
    A list box can have many columns. Change the 0 in the code to choose which column's data is required. The columns are counted from left to right but start with 0(Zero). So the first column is 0, the second is 1, the third is 2 etc.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    marcustofeles is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2011
    Posts
    23
    @hertfordkc
    I will try to dive in this dirty-thing and see if I can understand it. So far I don't really get it but I need to study both VBA and SQL I think...

    @
    Bob Fitz
    I tried your suggestion but to no avail.

    Thanks for your tips guys.

    Br Marcus

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Bob Fitz
    I tried your suggestion but to no avail.
    Before posting my solution I tested it to be sure that it worked.

    Can you confirm the following points please.

    1) The code is used as the Control Source property of the text box.
    2) The code includes the equals sign.
    3) You have replaced NameOfListBoxControl with the name of your list box control.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    marcustofeles is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2011
    Posts
    23
    Hi Bob,

    Yes, I can confirm those three statements.

    With your properties in place the textbox shows this value: #Name? (I have Access in my native language but #Name? is the obvious translation).

    Could the problem have to do with the properties of the listbox? Here's the setup:


    • I have a table with two fields, Prefix and Unique_number. The unique number always have a designated Prefix, so these two fields are on every row related/connected.
    • In the form I have a combox which source is the Unique_number field of the table.
    • The listbox is based on a query which checks which number has been chosen and then returns the related Prefix. That query looks like this: [Forms]![myForm]![number]



    Going nuts over this...

  7. #7
    marcustofeles is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2011
    Posts
    23
    Also, the values of the listbox and combobox are not stored anywhere. What I'm trying to do is to copy these two values and pasting them into the mentioned textbox, and that will then be stored in a table along with other controls of the form.

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    The appearance of #Name? in the text box would suggest that Access does not recognize the name of the list box control.

    Please cut and paste what you have as the Control Source property of the text box.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    marcustofeles is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2011
    Posts
    23
    The listbox is named prefix

    The control source property of the textbox is:
    =[prefix].[Column](0)

  10. #10
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Can you post a copy of your db?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  11. #11
    marcustofeles is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2011
    Posts
    23
    Would it be allright if I send you a private message with info on where to download? This is company stuff and I don't want to get into trouble...

  12. #12
    marcustofeles is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2011
    Posts
    23
    I just remembered a great way (www.sprend.se) to share files, but I would need your e-mail address if that's allright? I won't misuse it.

  13. #13
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    It would be better if you could post a copy to the forum.

    Just remove all "Real" data and replace with a 2 or 3 records worth of made-up data.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  14. #14
    marcustofeles is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2011
    Posts
    23
    I'm an idiot, I don't need your e-mail. You have a PM shortly with a download url.

  15. #15
    marcustofeles is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2011
    Posts
    23
    Oops, saw your message to late. Ok, I'll edit the DB and post it here.

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

Similar Threads

  1. Replies: 12
    Last Post: 06-08-2012, 02:37 AM
  2. Unable to search record in my listbox
    By mar_t in forum Access
    Replies: 7
    Last Post: 07-27-2011, 07:37 PM
  3. Replies: 0
    Last Post: 03-14-2011, 08:38 AM
  4. Populate unbound listbox with VBA
    By usmcgrunt in forum Forms
    Replies: 1
    Last Post: 09-23-2010, 09:11 PM
  5. Replies: 3
    Last Post: 08-25-2010, 09:03 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