Populating field from another form

  • Thread starter AccessQuestions
  • Start date
A

AccessQuestions

I am trying to open a form from another form if a check mark is check, and
have a field in the newly open form automatically populated with the primary
field value. I have the new form opening when the check mark is checked, and
I am using an If statement to do so. However, now I needed the primary field
on the newly opened form populated with primary field from the current form.
Can someone help me with this. I am a little new with this stuff.
 
K

Keith Wilby

AccessQuestions said:
I am trying to open a form from another form if a check mark is check, and
have a field in the newly open form automatically populated with the
primary
field value. I have the new form opening when the check mark is checked,
and
I am using an If statement to do so. However, now I needed the primary
field
on the newly opened form populated with primary field from the current
form.
Can someone help me with this. I am a little new with this stuff.

Try passing the value to the opening form in the OpenForm method's OpenArgs
argument. Assuming your value is stored in a text box called "txtID" on the
calling form:

DoCmd.OpenForm "frmMyForm", , , , , , Me.txtID

Then in the open event of the opening form, retrieve the value into your
text box:

Me.txtMyTextBox = Me.OpenArgs

HTH - Keith.
www.keithwilby.com
 
A

AccessQuestions

This is what I have in the opened form:

Private Sub CheckBox_Click()
Dim filtr As String
If Me.CheckBox = "-1" Then
stLinkCriteria = "[CaseId]=" & "'" & Me![CaseId] & "'"
DoCmd.OpenForm "Test", acNormal, , Me.CaseId
End If
End Sub

It opens the form called test. The form test is based on another table which
has a field called CaseID and I want the CaseID populated with the CaseID of
the current form. I placed the Me.CaseID = Me.OpenArgs in the on open event
of the "test" from but get debug errors.



Keith said:
I am trying to open a form from another form if a check mark is check, and
have a field in the newly open form automatically populated with the
[quoted text clipped - 6 lines]
form.
Can someone help me with this. I am a little new with this stuff.

Try passing the value to the opening form in the OpenForm method's OpenArgs
argument. Assuming your value is stored in a text box called "txtID" on the
calling form:

DoCmd.OpenForm "frmMyForm", , , , , , Me.txtID

Then in the open event of the opening form, retrieve the value into your
text box:

Me.txtMyTextBox = Me.OpenArgs

HTH - Keith.
www.keithwilby.com
 
K

Keith Wilby

AccessQuestions said:
This is what I have in the opened form:

Private Sub CheckBox_Click()
Dim filtr As String
If Me.CheckBox = "-1" Then
stLinkCriteria = "[CaseId]=" & "'" & Me![CaseId] & "'"
DoCmd.OpenForm "Test", acNormal, , Me.CaseId
End If
End Sub

It opens the form called test. The form test is based on another table
which
has a field called CaseID and I want the CaseID populated with the CaseID
of
the current form. I placed the Me.CaseID = Me.OpenArgs in the on open
event
of the "test" from but get debug errors.

What are the errors?

And do you mean you want to filter the opening form or populate a new record
with the value from the calling form? In this line

DoCmd.OpenForm "Test", acNormal, , Me.CaseId

Me.CaseId is the WHERE condition of the opening filter. Also I don't see
any sign of OpenArgs in the code you posted (incidentally, you don't need
the quotes around -1).

Could you clarify? If you want to filter then Klatuu's solution will work.

Regards,
Keith.
 
A

AccessQuestions

I need it to create a new record when the user would click the check mark.
The error that if give is the debug box and highligts the following Me.CaseId
= Me.OpenArgs in the opening form.

Keith said:
This is what I have in the opened form:
[quoted text clipped - 13 lines]
event
of the "test" from but get debug errors.

What are the errors?

And do you mean you want to filter the opening form or populate a new record
with the value from the calling form? In this line

DoCmd.OpenForm "Test", acNormal, , Me.CaseId

Me.CaseId is the WHERE condition of the opening filter. Also I don't see
any sign of OpenArgs in the code you posted (incidentally, you don't need
the quotes around -1).

Could you clarify? If you want to filter then Klatuu's solution will work.

Regards,
Keith.
 
R

Rick Brandt

AccessQuestions said:
I need it to create a new record when the user would click the check mark.
The error that if give is the debug box and highligts the following Me.CaseId
= Me.OpenArgs in the opening form.

If you have not supplied any OpenArgs then that error is to be expected. The
following line...

DoCmd.OpenForm "Test", acNormal, , Me.CaseId

....is not passing any OpenArgs value. If your intent is for Me.CaseId to be
passed as an OpenArgs value then you are missing a few commas...

DoCmd.OpenForm "Test", acNormal,,,,,Me.CaseId
 
A

AccessQuestions

I made the change that you suggested. The following is what I have on the
opening form:
Private Sub Form_Open(Cancel As Integer)
Me.CaseId = Me.OpenArgs
End Sub

The debug error is that is says I can't assign a value to this object.

Sorry..as mentioned I am a little new at this.
 
R

Rick Brandt

AccessQuestions said:
I made the change that you suggested. The following is what I have on the
opening form:
Private Sub Form_Open(Cancel As Integer)
Me.CaseId = Me.OpenArgs
End Sub

The debug error is that is says I can't assign a value to this object.

Sorry..as mentioned I am a little new at this.

It's not 100% consistent, but the Open event is often too soon to apply values
to controls on the form. Try the Load event instead.
 
A

AccessQuestions

It Worked!! Thank you so much.

So why the difference? Does the Load event pause a little longer then the
open event to allow the argument to work?

Rick said:
I made the change that you suggested. The following is what I have on the
opening form:
[quoted text clipped - 5 lines]
Sorry..as mentioned I am a little new at this.

It's not 100% consistent, but the Open event is often too soon to apply values
to controls on the form. Try the Load event instead.
 
R

Rick Brandt

AccessQuestions said:
It Worked!! Thank you so much.

So why the difference? Does the Load event pause a little longer then the
open event to allow the argument to work?

It has nothing to do with whether the argument worked. You can reference the
OpenArgs value from any event in a form.

Open is after the form has opened but before the RecordSet is loaded. Load is
after the Recordset is loaded. If you try to set the value of a bound control
before the Recordset is loaded you get that error.
 
A

AccessQuestions

Rick how are you with Reports? I just posted something in the report section,
can you take a look at it?
 
A

AccessQuestions via AccessMonster.com

I tried a couple of entries and the only way I could get it to add a new
record each time was to go to the test form and change the "data entry" value
to yes on the properites "data" tab. However, how would I make sure it
checks to see if the record exists before trying to add a new record with the
same ID?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top