Nice catch! I knew there must be something I was
missing. I am having to use a text type for the
equipment Id to accomodate some business rules.
Thank you for all your help!
Scott
-----Original Message-----
Hi Scott,
Is EqID a text field? I should have noticed that in stLinkCriteria
you have it quote wrapped so I am guessing that it is - change the
OpenArgs parameter to include the quotes and see what happens -
DoCmd.OpenForm stDocName, OpenArgs:="'" & Me.EqID & "'"
--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this
newsgroup.
Scott A wrote:
Unfortunately, I can't get the code to work. Here's what
I've got for the OnClick event in the parent form:
Private Sub cmdServiceSchedule_Click()
On Error GoTo Err_cmdServiceSchedule_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmServiceScheduleA"
stLinkCriteria = "[EqID]=" & "'" & Me![EqID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.OpenForm stDocName, OpenArgs:=Me.EqID
Exit_cmdServiceSchedule_Click:
Exit Sub
Err_cmdServiceSchedule_Click:
MsgBox Err.Description
Resume Exit_cmdServiceSchedule_Click
I didn't think there would be any problem keeping the link
criteria - thought it might be of some use, but could just
be junk code at this point.
Here's what I have on the child form's BeforeInsert event:
Private Sub Form_BeforeInsert(Cancel As Integer)
If Len(Me.OpenArgs & "") > 0 Then
Me.EqID = Me.OpenArgs
End If
End Sub
I can get all the way to the end of a record in the child
form, save the new record, and nothing appears in the EqID
field.
If it makes any difference, I'm using Access 2000. Maybe
should have said that up front...
-----Original Message-----
Why of course there is hope for you! You found the right place to
ask the questions, now we just have to try to provide the
answers.
Your scenario is perfectly reasonable - though it might be easier
to accomplish this with a simple form/subform, linked on EqID.
If you do want to stick with the second standalone form, I would
make a couple of recommendations - first change the name to drop
the 'sub' since that implies that it is a subform, rather than a
related or linked form. Note that the forms themselves do not
necessarily have a connection but your application, via the
command button, is linking them.
The code I gave you should be sufficient since it opens the form
in add mode (preventing the user from viewing any other records)
and it automatically fills in the foreign key field (Eqid) as
soon as the user begins to insert a new record. Note that the
BeforeInsert event occurs when the user types the first
character in a new record, but before the record is actually
created (from Access Help).
--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this
newsgroup.
Scott A wrote:
Is it a form, or is it a subform? Tough question!
It is a standalone form that I have linked to an existing
form using one of the Wizards... When setting it up, I
did ask it to basically filter the information displayed
on the child based on the record displayed in the parent.
I just named it 'sub' to differentiate it from the other
forms in the database.....
I'm still not sure I'm going about this the right way - it
seems this should be so much easier to do, especially
since I've already got relationships established between
these two tables, etc, bla bla.. Should I be basing the
second form on a query that already includes the EqID?
My intention is to provide a pop-up form that allows the
user to add service records ONLY to the piece of equipment
displayed in the parent form, which I'm guessing means
that I want to filter the second form based on the EqID of
the record displayed AND pass the value to the child form.
Is there any hope for me?
-----Original Message-----
Hi Scott,
The code you currently have is only going to filter the second
form based on EqId. You need to use a combination of OpenArgs
in the calling form and a BeforeInsert event in the called form
(subfrmServiceSchedule).
Modify your click event to be something like this:
Private Sub cmdServiceSchedule_Click()
On Error GoTo Err_cmdServiceSchedule_Click
Dim stDocName As String
stDocName = "subfrmServiceSchedule"
DoCmd.OpenForm stDocName,,,,,,me.eqid
' or more succintly:
' DoCmd.OpenForm stDocName,openargs:=me.eqid
Exit_cmdServiceSchedule_Click:
Exit Sub
Err_cmdServiceSchedule_Click:
MsgBox Err.Description
Resume Exit_cmdServiceSchedule_Click
Then in the BeforeInsert event
of 'subfrmServiceSchedule' you would
have something like the following:
Private Sub Form_BeforeInsert(Cancel As Integer)
If Len(Me.OpenArgs & "") > 0 Then
Me.EqID = Me.OpenArgs
End If
End Sub
One thing that needs clarification - is this
form 'subfrmServiceSchedule'
really a subform or is it a standalone form? The way you
reference it would be different if it is a subform.
--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this
newsgroup.
Scott A wrote:
I'm trying to start a new record - I'd like to
automatically pass the Equipment ID to the new form, just
because it's not relevant to the user and I don't want
them to have to type it in themselves.
If I were to implement this code (the first one you've
provided), I assume I need to modify the existing OnClick
event procedure. Here's what is in there already:
Private Sub cmdServiceSchedule_Click()
On Error GoTo Err_cmdServiceSchedule_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "subfrmServiceSchedule"
stLinkCriteria = "[EqID]=" & "'" & Me![EqID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdServiceSchedule_Click:
Exit Sub
Err_cmdServiceSchedule_Click:
MsgBox Err.Description
Resume Exit_cmdServiceSchedule_Click
I assume that the existing event describes the linked
properties of the two forms, and was also assuming that
this code would pass the data between the forms. If this
is not the case, where do I insert the acAdd statement?
.
.
.