Results 1 to 6 of 6
  1. #1
    ionline is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    3

    Unhappy Please Help Me about My Code

    I want to populate my text box on the form with the help of combo box.For this purpose i use the following code.
    Private Sub cmbx_AfterUpdate()
    Me.txtFirstName.Value=Me.cmbx.Column(1)


    Me.txtLastName.Value=Me.cmbx.column(2)
    End Sub




    The code work well when i try it for the first time.but when i close the form and reopen it,the combo box is fail to populate the text box on the form and the text box remain blank.I try break point also,delet all the old files and make new files but my problem is as it is.
    Please let me know by any experience person that how to solve my problem .
    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    Do you want to save these values to fields in table? Why? Are the textboxes bound to fields?

    If you don't need to save the values, just display them, VBA is not needed. Textbox ControlSource property can reference the combobox:

    =[cmbx].[Column](1)

    Your combobox is named cmbx? Not a very informative name.

    Column index begins with 0 so that means column 1 is index 0.
    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. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is the ComboBox bound (does it have a ControlSource)? You only get an AfterUpdate event when the value changes, but you knew that right?

  4. #4
    ionline is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    3
    Quote Originally Posted by RuralGuy View Post
    Is the ComboBox bound (does it have a ControlSource)? You only get an AfterUpdate event when the value changes, but you knew that right?
    No the combo box is not bound.It Takes values from another source table.

  5. #5
    ionline is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    3
    Quote Originally Posted by June7 View Post
    Do you want to save these values to fields in table? Why? Are the textboxes bound to fields?

    If you don't need to save the values, just display them, VBA is not needed. Textbox ControlSource property can reference the combobox:

    =[cmbx].[Column](1)

    Your combobox is named cmbx? Not a very informative name.

    Column index begins with 0 so that means column 1 is index 0.
    No i required to save the value so i need to be use VBA.My VBA code work only for the first time .When i close and reopen the form .then the code did not work.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    Your code saves data to record. As RuralGuy pointed out, the code only executes when the combobox value is changed.

    If you want the saved values to display from record, then set textbox ControlSource property to field.
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 06-28-2013, 12:58 PM
  2. Report Code is not allowing return to main code
    By rcwiley in forum Programming
    Replies: 2
    Last Post: 06-16-2013, 10:31 AM
  3. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  4. Replies: 1
    Last Post: 05-04-2013, 12:19 PM
  5. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 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