Open a form and pre-populate a text box

Chrism2

Registered User.
Local time
Today, 06:50
Joined
Jun 2, 2006
Messages
161
Hi folks,

I have a form called frmCustomerList; allowing a user to search and find a customer. When a user finds a customer, there are two buttons, one opens an edit customer form, called frmEditCompany through the following code

Code:
Private Sub butEdit_Click()
On Error GoTo Err_butEdit_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    
     stLinkCriteria = "CustomerID = '" & Me.CustomerID.Value & "'"

    stDocName = "frmEditCompany"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_butEdit_Click:
    Exit Sub

Err_butEdit_Click:
    MsgBox Err.Description
    Resume Exit_butEdit_Click
    

End Sub

This works fine.

However, I have/need another button next to it that opens another form called frmSaleEntry and starts a sale for the selected company.

this form has combo box (cboCompanyName) which allows the user to select the company in question. This forms works fine normally, but I want this field pre-populated when you link to it via frmCustomerList and the above code method doesn't cut it. cboCompanyName pulls down a list of companies with data from a table called tblCustomers, field name CompanyName.

Any clues on how to open a form and pre-populate this combo.

Many thanks!!!
 
It looks like to me you will need to setup your relationships in your database.

How are you handling how these tables to be linked to each other?

If you have a one to many relationship with customers being the one and orders for the customer being the many, this is an easy thing to do with Access.

Personally, I would use a list box that is connected to your tblCustomers. Then you can open the order form via the double click properties on your list box.

Or you could have an Enter order button that opens the order form for you.

Check out the sample databases..

Ken Higgs has a good one that should do what you are asking.

http://www.access-programmers.co.uk/forums/showthread.php?t=99777
 
Immediately after opening the second form:

Forms!SecondFormName.ComboName = Me.Whatever

Replacing the names in red as appropriate.
 

Users who are viewing this thread

Back
Top Bottom