Full Version: Passing field to new record
UtterAccess Discussion Forums > Microsoft® Access > Access Tables + Relationships
in2god01
I'm trying to setup a way so that when a user clicks on a command button, it opens a form and puts the current field value in the new record in the next table.

I've setup the one to many relationship with the field between the two tables being equipmentnumber.

here's the code i've used.

CODE


DoCmd.OpenForm "frmSupplyHistory", acNormal, _
    , "[EquipmentNumber] = " & EquipmentNumber, acFormAdd, , EquipmentNumber


This works for a different form that does the same thing, but won't work for this one. Not sure what i'm doing wrong.

Patrick
treeless
If EquipmentNumber is a string you need to add quotes to the WhereCondition

"[EquipmentNumber] = ' " & EquipmentNumber & " ' " (note spaces added between ' and " for clarity)

That's the only thing I see that could be wrong.
in2god01
I've attached a copy of what i'm referring to.

You'll get a couple errors b/c i didn't include all of the forms.

If you open it up and double click on the first record's model number, then there are two buttons

Place Service Call and Place Supply Call.

The service call works, the supply doesn't.

Not sure if it's in the relationship or what.

I've unhidden the fields so that i can see if the equipmentnumber goes to the new record or not.

I know my terminology isn't the greatest, but just don't know how to word things sometimes.
It's gotta be something simple b/c i haven't done any work on this db in a while.

Thanks,

Patrick

Edited by: in2god01 on 05.07.04.
treeless
Where are you trying to open the form? The reference to EquipmentNumber will only work if you are trying to open it from the frmCustomerInformationSubform.

To reference from the main form use [frmCustomerInformationSubform].[Form]![EquipmentNumber]
R. Hicks
I haven't looked at you attached file ... but ...
You are setting the criteria in the "where" argument .. then trying to open the form to a "new record" ...

That dog will never hunt ....

RDH
in2god01
man, it's bad when i can't remember how i set this up.

I want to use the equipmentnumber on the FrmEquipmentInformation in the frmSupplyHistory.

The Equipmentnumber is on the frmEquipmentInformation, but hidden.

When you click on place service call, it inserts it in the frmServiceCall.
When i do the same thing to make it go into supplyHistory, it doesn't work.

Thanks,

Patrick
in2god01
Well, unless the way i'm wording this is wrong, the dog does hunt.. ;-)

If you look at the database you can see the relationships i have setup and sorta what i'm trying to do.

Thanks for the help.

Patrick
R. Hicks
Did you see my reply ???

That problem needs to be addressed if you are attempting to pass the value use the OpenArgs ...

RDH
R. Hicks
You can not use the "where" argument to filter the form to a specific record then tell the form to open as a new record ...

That is what you are doing in your code ...

RDH
in2god01
The way it works now is when i click on Place Service Call, it opens up the frmServiceCall and uses the EquipmentNumber in the EquipmentInformation form and puts it in the ServiceCall Table for referential integrity.

That's all i'm trying to do. So what i did was made a new table with an autonumber, equipment number to rerence the piece of equipment, and the rest of the data. Then setup the relationship, and changed the place supply call to the way the place service call works. But it won't pass the equipment number over to the supplyhistory table i created.

Patrick
R. Hicks
That's not what the line of code you posted will do ...

"acFormAdd" ... says open the form to a "new record" ...

RDH
in2god01
okay.... i finally looked back to a post i did a LONG time ago and found that on the form FrmSupplyHistory, i need to have the OnCurrent to have Me![EquipmentNumber] = Me.OpenArgs.

now when i use the original code, it works.

I knew it was something i was missing.

Patrick
R. Hicks
If you are using:
CODE
DoCmd.OpenForm "frmSupplyHistory", acNormal, _    

, "[EquipmentNumber] = " & EquipmentNumber, acFormAdd, , EquipmentNumber

I don't see how it could possibly work ...

It should be something like this:
CODE
DoCmd.OpenForm "frmSupplyHistory", , , , acFormAdd, , Me.EquipmentNumber

RDH
in2god01
Here's the original post i went back to and figured out how to make it work.
There may be an eaiser way, but this worked for me.

Thanks for the help.

http://www.utteraccess.com/forums/showflat...rt=all&vc=1

Patrick
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.