Transfer ContactID to Secondary Form

D

Doctor

I need to send information from the main form (ContactInfo) to another form
(RegistrationInfo). The only thing I really need to send is the ContactID.
Right now, I can get access to display a registration only if one already
exists for the contact. But if no previous record exists I want to be able to
create a new registration in the RegistrationInfo form based on the ContactID.

Access 2003.

I'm very new to VB.

Thanks in advance.
 
K

Klatuu

I would suggest using the OpenArgs argument of the OpenForm method (see VBA
Help for details) to pass the ContactID to the Registration form. Then in
the Load event, use a FindFirst to determine whether the Contact exists. If
it does, make it the correct record. If it does not, create a new record and
populate the ContactID field with the value received from the main form.

So, where you open the form:

Docmd.OpenForm "RegistrationInfo", , , , , , Me.ContactID
'Other options left out for example

Then in the Load event of RegistrationInfo

Dim strContactID As string

If Not IsNull Me.OpenArgs Then
strContactID = Me.OpenArgs
With Me.RecordsetClone
.FindFirst "[ContactID] = '" & strContactID & "'"
If .Nomatch Then
docmd.GotRecord , , acNewRec
Me.txtContactID = strContactID
Else
Me.Bookmark = .Bookmark
End If
End With
End If
 
D

Doctor

Thanks for the help.

I loaded the code, but the "If not IsNull Me.OpenArgs Then" is in red.

Here is the code as loaded into the Registration Form:

Private Sub Form_Load()

Dim strClubberID As String

If not IsNull Me.OpenArgs Then
strClubberID = Me.OpenArgs
With Me.RecordsetClone
.FindFirst "[ClubberID] = '" & strClubberID & "'"
If .NoMatch Then
DoCmd.GotRecord , , acNewRec
Me.txtClubberID = strClubberID
Else
Me.Bookmark = .Bookmark
End If
End With
End If


End Sub


Klatuu said:
I would suggest using the OpenArgs argument of the OpenForm method (see VBA
Help for details) to pass the ContactID to the Registration form. Then in
the Load event, use a FindFirst to determine whether the Contact exists. If
it does, make it the correct record. If it does not, create a new record and
populate the ContactID field with the value received from the main form.

So, where you open the form:

Docmd.OpenForm "RegistrationInfo", , , , , , Me.ContactID
'Other options left out for example

Then in the Load event of RegistrationInfo

Dim strContactID As string

If Not IsNull Me.OpenArgs Then
strContactID = Me.OpenArgs
With Me.RecordsetClone
.FindFirst "[ContactID] = '" & strContactID & "'"
If .Nomatch Then
docmd.GotRecord , , acNewRec
Me.txtContactID = strContactID
Else
Me.Bookmark = .Bookmark
End If
End With
End If

--
Dave Hargis, Microsoft Access MVP


Doctor said:
I need to send information from the main form (ContactInfo) to another form
(RegistrationInfo). The only thing I really need to send is the ContactID.
Right now, I can get access to display a registration only if one already
exists for the contact. But if no previous record exists I want to be able to
create a new registration in the RegistrationInfo form based on the ContactID.

Access 2003.

I'm very new to VB.

Thanks in advance.
 
S

Stuart McCall

If Not IsNull Me.OpenArgs Then

That needs to be:

If Not IsNull(Me.OpenArgs) Then

IsNull is a function and all calls to functions should pass arguments inside
parantheses.
 
J

John W. Vinson

I need to send information from the main form (ContactInfo) to another form
(RegistrationInfo). The only thing I really need to send is the ContactID.
Right now, I can get access to display a registration only if one already
exists for the contact. But if no previous record exists I want to be able to
create a new registration in the RegistrationInfo form based on the ContactID.

Why not just make the second form a Subform of the first, using ContactID as
the master/child link field? No code needed at all!

John W. Vinson [MVP]
 
D

Doctor

Yes, that would take care of it except that the button that begins this
process is already in a subform. I know that one subform could be inside
another subform. But mostly, I'm out of room on my form. (asthetically
speaking).

Would you still do it?
 
D

Doctor

Great! Thanks, that took care of that.

Now. It errors out on the "GotRecord" command. The error says, "Compile
error: Method or data member not found" I searched in the help, but found
nothing that fixed it.

Sorry about all of the high maintenance questions.
 
D

Doctor

I just discovered why I couldn't find help on GotRecord--Because it is
supposed to be GoToRecord. Right?


What is the "txtClubberID = strClubberID" doing? On the "txtClubberID", VB
is giving the same error as before: "Compile error: Method or data member not
found"

I think that it is supposed to set the value of the ClubberID field in the
new form if it is not set already.
 
K

Klatuu

Stuart's answer is correct. Sorry, when you write code in the newsgroup, it
doesn't show syntax errors.
--
Dave Hargis, Microsoft Access MVP


Doctor said:
Thanks for the help.

I loaded the code, but the "If not IsNull Me.OpenArgs Then" is in red.

Here is the code as loaded into the Registration Form:

Private Sub Form_Load()

Dim strClubberID As String

If not IsNull Me.OpenArgs Then
strClubberID = Me.OpenArgs
With Me.RecordsetClone
.FindFirst "[ClubberID] = '" & strClubberID & "'"
If .NoMatch Then
DoCmd.GotRecord , , acNewRec
Me.txtClubberID = strClubberID
Else
Me.Bookmark = .Bookmark
End If
End With
End If


End Sub


Klatuu said:
I would suggest using the OpenArgs argument of the OpenForm method (see VBA
Help for details) to pass the ContactID to the Registration form. Then in
the Load event, use a FindFirst to determine whether the Contact exists. If
it does, make it the correct record. If it does not, create a new record and
populate the ContactID field with the value received from the main form.

So, where you open the form:

Docmd.OpenForm "RegistrationInfo", , , , , , Me.ContactID
'Other options left out for example

Then in the Load event of RegistrationInfo

Dim strContactID As string

If Not IsNull Me.OpenArgs Then
strContactID = Me.OpenArgs
With Me.RecordsetClone
.FindFirst "[ContactID] = '" & strContactID & "'"
If .Nomatch Then
docmd.GotRecord , , acNewRec
Me.txtContactID = strContactID
Else
Me.Bookmark = .Bookmark
End If
End With
End If

--
Dave Hargis, Microsoft Access MVP


Doctor said:
I need to send information from the main form (ContactInfo) to another form
(RegistrationInfo). The only thing I really need to send is the ContactID.
Right now, I can get access to display a registration only if one already
exists for the contact. But if no previous record exists I want to be able to
create a new registration in the RegistrationInfo form based on the ContactID.

Access 2003.

I'm very new to VB.

Thanks in advance.
 
T

tbrogdon

Why not just make the second form a Subform of the first, using ContactID as
the master/child link field? No code needed at all!

John W. Vinson [MVP]

I am very sorry to intrude on this conversation but this is exactly
what I am asking about in another post but I guess I haven't asked the
question very clearly. I tried making autoforms of what would be
ContactInfo and RegistrationInfo in this instance and dropped
RegistrationInfo into ContactInfo but I am having issues with what
would be the ContactID field in RegistrationInfo populating for all my
subesequent entries in RegistrationInfo. Most importantly, when I
autoformed ContactInfo, Access automatically created a datasheet
subform of RegistrationInfo - but I need it to be a continuous form
and can't figure out how to accomplish that.

I am probably misunderstanding the relationship between my Main form
and my subform. I tried putting a command button on my Main form whose
OnClick event would set the ContactID for RegistrationInfo.ContactID.
That failed and I am beginning to see that it is impossible to
populate those fields before a record has been created....

But instead what I have accomplished is a "hornet's nest."

Any advice and guidance would be greatly appreciated...and thanks
again for your time.

Tim
 
J

John W. Vinson

Yes, that would take care of it except that the button that begins this
process is already in a subform. I know that one subform could be inside
another subform. But mostly, I'm out of room on my form. (asthetically
speaking).

Would you still do it?

Probably; I'd use a Tab Control on the form to manage screen real estate. The
separate popup form will work too, but I find it both harder to manage as a
developer, and less intuitive for the user.

John W. Vinson [MVP]
 

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