Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to transfer values from one form to another as I select a value

Status
Not open for further replies.

infoscion

Technical User
Jan 21, 2005
50
0
0
US
Hi:
I am working on a form where the user needs to enter some preliminary customer information(like customer_ID and customer_name). After the information has been stored, as the user selects the Id, another form pops up that serves as an interface to enter more detailed information about the customer. The new form that pops up needs to take the ID and the name of the customer from the previous form. I tried working with the After Update event of access, but I get a very cryptic error message. Any ideas will be greatly appreciated.
Info
 
Have a look at the OpenArgs action in the help files.
 
Hi:
Thank you for leading me to open args action.
Regards,
Info
 
I'm not sure how your first form is setup. But one way that I do this is I will have a combobox on form1 with the id as a hidden column. Then from form2, I can get this id and use it in a SQL statement to get the right record on form2.

So in form2, you can write:

Dim myID as integer

myID = Form_frmForm1.cboCombo.Column(1)

You can basically access anything from the first form while you are in any event of the second form by referencing the form name (make sure you preface it with Form_)

Maybe there is an easier way, but it works for me. Hope this helps. :)
 
Lots of ways to do this, the simplest is
on open arg
me.Id = Forms![Form1].Id
 
Hi:
Thank you very much for all the tips. Yes, I am having trouble executing the code. I have a list box that has the customer Id and the Name. As i select a customer and hit Ok, a new form that allows me to enter all the details about that customer should pop up and the ID ( a text box)and the name ( another text box ) need to be populated in the newly popped up form. Then I can go ahead and fill in some other fields and then finally add the records to a table.
I am not sure as to why it is not working.
Regards
Info
 
I'll try to help you some more if you can provide more detail. What do you have working now and what code do you have?
 


Hi:
Here is the code. I do not get an error message but it does not accomplish anything. On the form ADD_Customer DETAILS I need to populate the customer_ID text field with values from ADD_customer_form. Add_customer_form has a list box that has two columns (customer_ID and customer_Name). When I select a customer record and I hit OK, I want ADD_Customer_DETAILS to pop up with the the customer_ID already populated from the ADD_Customer form.



Private Sub OK_Click()
'when user clicks this button
'please transfer the record to the new form taht is add_patient_details
Dim Customer_ID As String
Customer_ID = Form_add_customer_records.SelectCode.Column(1)

'DoCmd.OpenForm "add_customer_details", WhereCondition:="Text0=" & SelectCode

end sub

Please take a look at this and advise me.
Regards,
Info
 
In the click event on form1 - Add_Customer form:

Private Sub OK_Click()
docmd.openForm "Add_Customer_Details"
end sub

In the form load event on form2 - Add_Customer_Details form:

Private Sub Form_Load()
Dim myCustomerID as integer
myCustomerID = Form_Add_Customer.lstboxName.Column(0)
customer_ID.SetFocus
customer_ID.text = myCustomerID
End Sub

I didn't know what the name of your list box was so substitute the name for lstboxName; Also, I put Column(0) but if the ID is in Column(1), change to that instead.

Let me know if this works for you. :)
 
I should have said combobox rather than listbox but it works the same as far as accessing the columns. You can also use this same concept to get any other data you need from form 1. Hope this helps. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top