Set Value on Form open

AnnPhil

Registered User.
Local time
Today, 22:17
Joined
Dec 18, 2001
Messages
246
Is it possible to set value of a field when form opens, based on a field from another form?
For example, user opens a form that lists all companies, user selects a company for the job, user then clicks button that opens another form which is set to go to a new record, i would like the companyID field in this second form to be set to the companyid that was selected on the first form.
Any suggestions?

Thanks
 
I'm trying to do the same thing.....what did you have to do to make this work? Thanks

Kacy
________
Kitchen Measures
 
Last edited:
I've done this recently.

First trap the value you would like to pass over in a variable, say, "CurrentValue". In your calling form, under whatever event calls the form to open (say, a command button) include this code;

DoCmd.OpenForm <NewFormName>, , , , acFormAdd
[Forms]![NewFormName]![NewFormControl] = CurrentValue

Where NewFormName is the name of the form you are calling, and NewFormControl is the name of the object you would like to pass the variable into.

DaveMere
 
Here is what i did:

The following code is tied to a command button on the first form

DoCmd.OpenForm "SecondForm", acNormal

Forms![SecondForm]![CountyID] = Forms![FirstForm]![CountyID]

Works great! Hope this helps
 
I'm still having trouble passing what I have in my combo box in a form (My_Switchboard) to the Title of my report (Weekly). Here's the code that I'm running.

Private Sub Command13_Click()
DoCmd.OpenReport "Weekly", acNormal

[Reports]![Weekly]![Text18] = [Forms]![My_Switchboard]![Combo8]
End Sub


Here's the error that I'm receiving when I run it.

Run-time error 2451

"The reeport name 'Weekly' you entered is misspelled or refers to a report that isn't open or doesn't exist."

Any help would be appreciated.

Thanks
Kacy
________
Milf mature
 
Last edited:
Change the code on your Switchboard button to just open the report, then add the following code to the field in the report:
=[Forms]![My_Switchboard]![Combo8]
That should work.
 
AnnPhil,

I am getting closer to the answer....What I did was in the control source of the textbox on the report I put.......

=[Forms]![My_Switchboard]![Combo8] .

This is displaying the Facility_ID instead of the Facility Name. In my combo box I have the Facility_ID and Facility_Name, but only Facility_name is being displayed in the combobox. Do you have any suggestions on displaying the name instead of the ID. Thanks in advance.

Kacy
________
Ipad accessories
 
Last edited:
You could try DLookUp() function.


ThisField=DLookUp("[Faculty_Name]","[MyTable]","[Faculty_ID]
=[Forms]![My_Switchboard]![Combo8]")



(It's all one line...)

HTH

Dave E
 
=[Forms]![My_Switchboard]![Combo8].Column(1) where column 1 is the second column in your combo
 

Users who are viewing this thread

Back
Top Bottom