Solved

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

Posted on 2016-08-12
1
98 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

635 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