Copying field values between forms

csuwildlifer

New member
Local time
Today, 14:15
Joined
Oct 25, 2012
Messages
2
I have been trying to figure this out for days now, and it must be something simple that i am missing...

I have a form ("FieldChecks") that i enter information in when i am working in the field. There are two different text boxes that identify an individual ('CID' and 'Permit'). [An individual can have either a 'CID' (Customer Identification) or 'Permit' number (or both).] I am trying to set up a button that i click on the "FieldChecks" form that will open another form ("HarvestInfo"), and copy the 'CID' and/or 'Permit' number directly to the corresponding fields in the new "HarvestInfo" form.

Right now, i have tried using the OpenArgs in VBA and messing with the macros, and either get an error message, or the "HarvestInfo" form opens without the 'CID' or 'Permit' numbers.

As a newbie, i have tried to tailor other posts/code to my specific needs without success... some guidance in the proper direction would be much appreciated!
 
You create a button and cancel the wizard. Right click on your button and get to the code generator. Enter the following:

private sub NameOfYourButton_Click()
docmd.openform "HarvestInfo"
form_harvestinfo.CID = me.CID
form_harvestinfo.Permit = me.Permit
end sub

I have presumed that the fields on both FieldChecks and Harvestinfo are CID and Permit, but you just change it into what ever names they have!~)
 
...by the way before this works you have to go to design view on HarvestInfo and set HasModule to true...
 
You can also so use the OpenArgs property of the OpenForm method to pass information between the calling form and the form being called.

The OpenArgs can then be tested in the called form's On Load event.
 
Last edited:
Right now, i have tried using the OpenArgs in VBA and messing with the macros, and either get an error message...

OpenArgs is one of the most misunderstood arguments in the OpenForm method. Essentially all you are doing is passing a variable to the named form. This is down to you to create a format for passing the info. (1 piece of info just pass as is, but multiple pieces of data you just seperate with a charcter that is not likely to be encountered in your data, EG / ? - etc). The named form has no way to interpret the OpenArg value unless you tell it how.This is done in the Open event of the form.

So for your scenario you would open the form with something like;
docmd.openform "HarvestInfo",,,,,me.cid & "/" & me.permit

In the HarvestInfo Open event you would do something like this;

If Me.OpenArgs = true Then
Me.CID = left(me.openargs,(instr(me.openargs,"/"))-1)
me.permit = right(me.openargs,len(me.openargs) -((instr(me.openargs,"/"))+1))

Hope this makes OpenArgs a little clearer:), I know it drove me nuts when i first started using it as i expected the opening form to understand what the data was and where it went.:banghead:



Doh! Looks like Big John got there before me.:D
 
Last edited:
Isskint your post adds some information that should help the OP in his understanding of the OpenArgs :D

I missed the bit where he says he'd already tried the OpenArgs :(
 
First of all: Severin - Perfect! Exactly what i needed! Thanks!
Second: Isskint - Thanks for the info. What you said makes sense (I think!) I think i bit off a bit more than i thought i could chew taking this project on. There's a learning curve i didn't expect to be so steep! John Big Booty - Thanks for the help and the welcome!
 

Users who are viewing this thread

Back
Top Bottom