Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access: How to set the selected value of combo box when opening form from code

Posted on 2016-08-12
1
Medium Priority
?
166 Views
Last Modified: 2016-08-12
I have a form with search results in a listbox, and I'd like to open the next form  with the chosen id prepopulated form the search. How do I do that?
Private Sub ContractNew_btn_Click()
    If (Me.PersonSearch_lst.Value > -1) Then
        Dim customerID As Integer
        customerID = Me.PersonSearch_lst.Value
        DoCmd.OpenForm "Order", acNormal
        DoCmd.GoToRecord acDataForm, "Order", acNewRec
        DoCmd.GoToControl "Customers_cbo"
        '"set Customers_cbo.Value = customerID"
    End If
    
End Sub

Open in new window


TIA
Dennis
0
Comment
Question by:Dennis_Gundersen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 31

Accepted Solution

by:
Helen Feddema earned 2000 total points
ID: 41754135
It might make more sense to run this code from the AfterUpdate event of the listbox but it should work from a button as well.  You need to set a Form variable to the newly opened form, and then set the value of the control on the form.  Try these changes (assuming that frm has been declared as Access.Form):

        DoCmd.OpenForm "Order", acNormal
        DoCmd.GoToRecord acDataForm, "Order", acNewRec
        Set frm = Forms("Order")
        frm![Customers_cbo].Value = customerID"

Open in new window


Also, if you set DataEntry to Yes for the Orders form, you don't need to go to the new record.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question