Results 1 to 13 of 13
  1. #1
    Join Date
    Nov 2022
    Posts
    11

    Question Question regarding import of combo box to text box

    Hi All,

    I am by no means a professional programmer, and I am also new to this forum. However, I have self-taught myself access and a lot of VB that goes with it. I enjoy using it for my work, and can't yet migrate to anything else.



    I have one form with a text box that has the name 'Job Titles'. On the other form I have the same combo box field 'Job Titles'. When the user clicks import on the form with the text box, it will not import the value to the combo box. Is there code or a way to execute this? I can import textbox to textbox just fine. However combobox value to a text box is not working for me.

    Thanks in advance! I am sure it is something simple.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,284
    I am not sure which direction you want the value to go to?, as you appear to contradict yourself?

    import the value to the combo box

    However combobox value to a text box is not working
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    use the full path

    forms!form1!txtBox = forms!form2!cboBox

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    How do you "import" on the form with the textbox? What is the row source of the combo box? You might need to requery the row source of the combo to get the new value to show up in the drop-down list:
    Code:
    Me.cboJobTitle.Requery
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Join Date
    Nov 2022
    Posts
    11
    Sorry let me clarify. I want the value to be passed from the text box on the one form to a combo box on the other. I hope this makes sense.

    @ranman256 - I am going to try your suggestion. Thank you!

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,284
    Quote Originally Posted by accessuser2023 View Post
    Sorry let me clarify. I want the value to be passed from the text box on the one form to a combo box on the other. I hope this makes sense.

    @ranman256 - I am going to try your suggestion. Thank you!
    Well you are going to have to swap that suggestion around.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Join Date
    Nov 2022
    Posts
    11
    Forms![form1]![JobTitle] = Forms![form2]![JOBTITLE]

    This is what I am using in a command button on click event.

    The rowsource of the combobox gets the values from a table called 'JobTitles' I am thinking this is where the 'issue' lies perhaps

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,284
    Quote Originally Posted by accessuser2023 View Post
    Forms![form1]![JobTitle] = Forms![form2]![JOBTITLE]

    This is what I am using in a command button on click event.
    Well you said the textbox was on form1 and the combo on form2 and you want the value from form1 to go to form 2?

    See anything wrong with that statement?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    As asked earlier, what is the row source of the combo; if the text box shows a descriptive job title (Manager) but the combo is bound to a numeric JobTitleID (i.e. 1 being the unique ID corresponding to the "Manager" record in a tblJobTitle lookup table) passing it directly like that won't work. This assumes the combo has a two column row source with the first one (ID) hidden. You would need to use a dLookup:

    Forms!frmWithCombo!JobTitle=dLookup("JobTitleID"," tblJobTitle","JobTitle='" & Forms!frmWithTextBox!JobTitle & "'")

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  10. #10
    Join Date
    Nov 2022
    Posts
    11
    @Gicu this was the issue and it worked. Thank you! The value has to already be in the job title table which is fine, but if it isn't, the field shows up blank. Would there be a way to easily code this to notify me or place the value in the combo box even if it is not in the table, so I can simply add it?

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    Of course there is, in your click event you can test for the value using a dCount (or the return value of the dLookup):
    Code:
    If dCount("*"," tblJobTitle","JobTitle='" & Forms!frmWithTextBox!JobTitle & "'")=0 Then
         If Msgbox("The select job title does not yet exist in the Job Titels table. Do you want to add it?",vbquestion +vbYesNo,"Add newjob title")=vbNo then Exit Sub 'skip updating the combo
        'if you got here the user wants to add it
        'open a modal\dialog form bount to the tblJobTitles in DataAdd mode and pass it the new value directly or as the OpenArgs
       docmd.OpenForm "popAddJobTitle",acNormal,,,acFormAdd,acDialog,Me.JobTitle 'using OpenArgs - in the Load event of the modal form add Me.JobTitle=Me.OpenArgs
       Forms!popAddJobTitle!JobTitle=Me.JobTitle ' directly into the now open form - ;this line needs the previous one but without the OpenArgs
    End If
    'now that the modal form is closed and the new value added to the table go ahead and update the combo
    Forms!frmWithCombo!JobTitle=dLookup("JobTitleID"," tblJobTitle","JobTitle='" & Me.JobTitle & "'")
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    Join Date
    Nov 2022
    Posts
    11
    This was all very helpful. My issue is fixed. Thanks for all of the help!

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    You're very welcome!
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. text file import question.
    By kevinh2320 in forum Access
    Replies: 4
    Last Post: 05-25-2017, 01:11 PM
  2. Replies: 1
    Last Post: 02-06-2016, 05:33 AM
  3. import text file with text date
    By rody in forum Import/Export Data
    Replies: 5
    Last Post: 09-01-2014, 12:50 AM
  4. Import text file question
    By sumdumgai in forum Import/Export Data
    Replies: 14
    Last Post: 03-23-2010, 07:59 AM
  5. Simple Question - Combo Box Default Text
    By sayitgreen in forum Forms
    Replies: 3
    Last Post: 02-20-2010, 12:59 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