Results 1 to 5 of 5
  1. #1
    siema24 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    22

    Problem with setting text box value based on combobox choice

    Hi,
    a have a small problem with text field value. Let me give you a simple example:
    I've created a table tblNameSurname with fields id, name, surmame. This is where I put actors details.


    Second table is tblFilmCrew with fields id, surname. Field surname is a numer field linked with id from tblNameSurname. This table I use for choosing actors that have a role in a new movie. Whatever

    For entering data to tblFilmCrew I use a form that is shown below:

    Click image for larger version. 

Name:	form_overview.png 
Views:	9 
Size:	12.0 KB 
ID:	27948

    It consists of a combobox 'surname' and a textbox 'name'. Although textbox is used just for additional information i want it to displaly an actor's name based on a surname choice. For this purpose I've created a combobox after_update event:

    Click image for larger version. 

Name:	surname_vbo.png 
Views:	9 
Size:	6.2 KB 
ID:	27949

    but unfortunately it doesn't work good - when a new actor is chosen all existing actors names change to a new-one name.
    In this example, if I choose "stone" as a new actor, then all affleck, freeman and clooney names will be replaced with "emma".

    Do you guys know how to fix it? Maybe there is a better and a more simple way to set textbox value based on combobox choice? Thank you!

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    it is because your name txtbox is unbound - so will be the same value for each record

    remove the vba code and put the assignment into the controlsource of the textbox like this

    =surname.column(2)

  3. #3
    siema24 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    22
    Hi,
    thank you, seems that your approach is fine. I've removed vbc code and put assignment into the textbox controlsource. However I'm able only to get into column(0) (which is useless ID field - 1,2,3,4...) by putting just "surname" into controlsource.
    Could you please confirm whether syntax =surname.column(n) is ok?

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    I'm assuming that 'surname' is the name of your combo

    However I'm able only to get into column(0)
    - that is because column 0 is the default value. You need the same. Access should add appropriate brackets but I would expect it to look like

    =[surname].[column](2)

  5. #5
    siema24 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    22
    unfortunately =[surname].[column](2) still doesn't work. Access adds brackets and changes it to: surname.[Column(2)]

    I'll try with a few other combinations, I'm sure that it's almost done...

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

Similar Threads

  1. Replies: 3
    Last Post: 12-29-2015, 04:06 PM
  2. Replies: 1
    Last Post: 03-27-2014, 06:42 AM
  3. Hide or disable value choice in combobox.
    By floyd in forum Programming
    Replies: 2
    Last Post: 11-16-2013, 12:20 PM
  4. Combobox setting other combobox values problem
    By maxmaggot in forum Programming
    Replies: 8
    Last Post: 06-30-2013, 07:18 AM
  5. Replies: 5
    Last Post: 07-23-2011, 11:48 PM

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