DoCmd.openform problems

G

Guest

I have a form (BatchTrackingEntryForm) with a subform (Descrepancy Query
Subform). I have added a command button that has an on click expression that
reads
Private Sub Command77_Click()
DoCmd.OpenForm "Descrepancies Query", , , "[Descrepancies
Query]![BatchID]=Forms![BatchTrackingEntryForm]![BatchID]", acFormAdd
End Sub
The (Descrepancies Query) form does open, but with the acFormAdd the
[BatchID] Field is blank instead of keeping it from the
(BatchTrackingEntryForm). I have tried severl different ways to keep the
[BatchID] field, like setting it in the criteria of the Descrepancy Query
=[Forms]![BatchTrackingEntryForm]![BatchID] but for some reason I just cant
get it to stay. Can someone help? Thanks in advance!
 
G

Guest

Ryan,

Your Where clause was using a literal of the "Forms![BatchTracking......."
instead of using the actual value. You need to close your quotes after the
equal sign and append the value of the forms control.

Try it like.

DoCmd.OpenForm "Descrepancies Query", , , "[BatchID]=" & Forms!
[BatchTrackingEntryForm]![BatchID], acFormAdd

BTW, It is so much easier to figure out what control you are looking at if
you change the name of the control from the default (in this case Command77)
to something more meaningful (cmd_Discrepancies). This makes reading and
debugging your code many, many times easier.

Dale
 
G

Guest

Dale,

I tried your code, and the [BatchID] field was there with the correct value.
Just like every other thing I have tried, when I update the (Descrepancy
Query Form) fields and close the (Discrepancies Query Form) the [BatchID]
field is blank and therefore does not show up on my (BatchTrackingEntryForm).
Just so you know the Primary key for the Discrepancies table is
[DescrepanyID] and the Primary key field for the BatchTracking table is
[BatchID]. I dont know if this helps but for some reason I cant get the
[BatchID] field to stay.

Dale Fye said:
Ryan,

Your Where clause was using a literal of the "Forms![BatchTracking......."
instead of using the actual value. You need to close your quotes after the
equal sign and append the value of the forms control.

Try it like.

DoCmd.OpenForm "Descrepancies Query", , , "[BatchID]=" & Forms!
[BatchTrackingEntryForm]![BatchID], acFormAdd

BTW, It is so much easier to figure out what control you are looking at if
you change the name of the control from the default (in this case Command77)
to something more meaningful (cmd_Discrepancies). This makes reading and
debugging your code many, many times easier.

Dale
--
Email address is not valid.
Please reply to newsgroup only.


Ryan said:
I have a form (BatchTrackingEntryForm) with a subform (Descrepancy Query
Subform). I have added a command button that has an on click expression that
reads
Private Sub Command77_Click()
DoCmd.OpenForm "Descrepancies Query", , , "[Descrepancies
Query]![BatchID]=Forms![BatchTrackingEntryForm]![BatchID]", acFormAdd
End Sub
The (Descrepancies Query) form does open, but with the acFormAdd the
[BatchID] Field is blank instead of keeping it from the
(BatchTrackingEntryForm). I have tried severl different ways to keep the
[BatchID] field, like setting it in the criteria of the Descrepancy Query
=[Forms]![BatchTrackingEntryForm]![BatchID] but for some reason I just cant
get it to stay. Can someone help? Thanks in advance!
 
G

Guest

BTW, if I take off the acFormAdd then it does show the Discrepancies that I
have already entered with the relating [BatchId]. I can add a new
Discrepancy but it does not keep the [BatchID] field.

Dale Fye said:
Ryan,

Your Where clause was using a literal of the "Forms![BatchTracking......."
instead of using the actual value. You need to close your quotes after the
equal sign and append the value of the forms control.

Try it like.

DoCmd.OpenForm "Descrepancies Query", , , "[BatchID]=" & Forms!
[BatchTrackingEntryForm]![BatchID], acFormAdd

BTW, It is so much easier to figure out what control you are looking at if
you change the name of the control from the default (in this case Command77)
to something more meaningful (cmd_Discrepancies). This makes reading and
debugging your code many, many times easier.

Dale
--
Email address is not valid.
Please reply to newsgroup only.


Ryan said:
I have a form (BatchTrackingEntryForm) with a subform (Descrepancy Query
Subform). I have added a command button that has an on click expression that
reads
Private Sub Command77_Click()
DoCmd.OpenForm "Descrepancies Query", , , "[Descrepancies
Query]![BatchID]=Forms![BatchTrackingEntryForm]![BatchID]", acFormAdd
End Sub
The (Descrepancies Query) form does open, but with the acFormAdd the
[BatchID] Field is blank instead of keeping it from the
(BatchTrackingEntryForm). I have tried severl different ways to keep the
[BatchID] field, like setting it in the criteria of the Descrepancy Query
=[Forms]![BatchTrackingEntryForm]![BatchID] but for some reason I just cant
get it to stay. Can someone help? Thanks in advance!
 

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