adding value from one form to another

Vegard

Registered User.
Local time
Today, 13:29
Joined
Jul 31, 2002
Messages
11
I'm sure there is a really easy answer to my question.. I don't seem to get it right though...

I have to forms based on to different tables..

This is the most important part of my forms:

Contact: ContactID, LastName, Firstname, CompanyID (lookup to a different table)

Prospect: ContactID (showing LastName, FirstName), CompanyID etc...

1. When I want to create a new Prospect, the user have 2 way to fill in the prospect.

1.1 If the Contact is already in the contactregister, I want to find his name in a combobox, then the company shows up automatic... I know how to create the combobox.

1.2 If the contact is not in the contactregister, I want a button that takes my to the contactfrm.. Then I want a button on the contactfrm, that opens up the prospectfrm and fills in contactname and company automatic. from the contactfrm..

Sorry for my lack of english.. I think!

Vegard
 
To automatically open Form2 from Form1, use the following code:

DoCmd.OpenForm "Form2"

To set the value of a control on Form2 to the same value as a control on Form1, from code running on Form1, use this code:

[Forms]![Form2]![some control] = Me![some other control]
 
Thanks.. That was not difficult at all.

And now I only need an answer to my first question. When I select Contactname, I want the company to fill in at once..

really love this messageboard..

vegard
 
Hmmm.. when i press the create new prospect button on the contact frm, the name and company SOMETIMES will not show on the prospect form. If I click on the companyfield, it becomes visible..

Is my database living it's own life?

Vegard
 
Use the combo box wizard to set up a combo box. The combo box will get its values from a table, query or SQL statement that includes both the contact and company fields (you seem to be storing this same data in 2 tables, which is generally very bad practice, but that's a separate issue). The combo box should display only the contact, but you can access the company associated with a particular contact by using the comb box's Column property. For example, if the combo box includes only the contact in the first column (visible) and the company in the second column (not visible), you could refer to the company associated with the currently selected contact as follows:

MyCombBox.Column(1)

To make the company automatically appear in a text box on the same form when a contact is selected from the combo box, set the text box's ControlSource property to:

=MyCombBox.Column(1)
 
How do I store that value that comes up in the unbound text box?
 
You can save the value in a text box either by assigning it to a table field before leaving the record or closing the form, as in:

MyTableField = MyUnboundTextBox

or, by binding the text box (setting its ControlSource property) to one of the fields in the table to which the form is bound.

If your project hasn't gone too far, you might want to consider re-structuring it so that you are not storing the same fields in two separate tables. For example, you might replace the Contact and Prospect tables with a single Contact table, and include a Status field to indicate whether the person was a contact, a prospect, etc. The Status field could be bound to a combo box on the data entry form, and that combo box could get its data from a separate StatusType lookup table. This would avoid the problems of copying data from one table to another, possible inconsistencies between the tables, etc. It would also allow you to add new StatusTypes without making any changes to your data entry form.
 

Users who are viewing this thread

Back
Top Bottom