Solved

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

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modal form 11 30
Access sql to sql server express 10 35
Change date stored as "short text" YYYYMMDD to MM/DD/YYYY? 27 28
2 IIF's in Access query 25 28
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

777 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