form code to link records!

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I have a database built that has several forms with
buttons in each to link each other for easy
viewing/switching of the forms. Each page displays info
about a patient, however, with different fields. When I
select a certain patient on the first form and click to
another form, the same patient doesn't come up, the new
form just reverts to the patient in record one. what code
do I use so that the same patient being viewed in the
current form comes up when I click on the button fo rthe
new form to display othe rinfo for te same patient?
Thanks!
 
Joe,

Try This:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormName"

stLinkCriteria = "[PatientID] = " & Me![PatientID] 'assuming PatientID
is a number

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

Assuming ButttonName is the name of the command button and PatientID is the
Primary Key and is a number.

Hint: You can use the command button wizard to open a form and display
certain records as well.

HTH,
Josh
 
I am trying to edit the code for this button n my forms
database. In the "PatientID" you refer to, would that be
the nam ein the properties field on the patient number box
I am trying to reference? I have several forms with a
command button structure that I nee dto edit code for each
of them. Each form has the patient ID 'name' in the
properties box different, so how do I go about coding each
button?

When I put the code in you told me and used "Acct #" in
plac eof Patient ID, a query box came up asking for me ot
input a record # (acct #). I just need the correct form
to pop up with the same patient info I was just working on
in one form to be displayed in the form I clicked on.
Thanks!
-----Original Message-----
Joe,

Try This:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormName"

stLinkCriteria = "[PatientID] = " & Me!
[PatientID] 'assuming PatientID
 
Joe said:
I am trying to edit the code for this button n my forms
database. In the "PatientID" you refer to, would that be
the nam ein the properties field on the patient number box
I am trying to reference? I have several forms with a
command button structure that I nee dto edit code for each
of them. Each form has the patient ID 'name' in the
properties box different, so how do I go about coding each
button?

When I put the code in you told me and used "Acct #" in
plac eof Patient ID, a query box came up asking for me ot
input a record # (acct #). I just need the correct form
to pop up with the same patient info I was just working on
in one form to be displayed in the form I clicked on.
Thanks!
-----Original Message-----
Joe,

Try This:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormName"

stLinkCriteria = "[PatientID] = " & Me!
[PatientID] 'assuming PatientID
is a number

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

Assuming ButttonName is the name of the command button and PatientID is the
Primary Key and is a number.

Hint: You can use the command button wizard to open a form and display
certain records as well.

HTH,
Josh




.
 
Joe,

If the unique primary key for a patient is a field called [Acct #] then
simply add this line of code before the DoCmd.OpenForm line in each of the
command button click events on each form:

stLinkCriteria = "[Acct #] = " & Me![Acct #]

So the resulting code should look some thing like this:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "YourFormName"
stLinkCriteria = "[Acct #] = " & Me![Acct #]

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

If you still can't get this to work, then try creating new buttons using the
command button wizard and choosing 'Open the form and Find Specific Data to
Display' instead of 'Open the form and Display all records' This will allow
you to choose the correct fields to link by.

HTH,
Josh

Joe said:
I am trying to edit the code for this button n my forms
database. In the "PatientID" you refer to, would that be
the nam ein the properties field on the patient number box
I am trying to reference? I have several forms with a
command button structure that I nee dto edit code for each
of them. Each form has the patient ID 'name' in the
properties box different, so how do I go about coding each
button?

When I put the code in you told me and used "Acct #" in
plac eof Patient ID, a query box came up asking for me ot
input a record # (acct #). I just need the correct form
to pop up with the same patient info I was just working on
in one form to be displayed in the form I clicked on.
Thanks!
-----Original Message-----
Joe,

Try This:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormName"

stLinkCriteria = "[PatientID] = " & Me!
[PatientID] 'assuming PatientID
is a number

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

Assuming ButttonName is the name of the command button and PatientID is the
Primary Key and is a number.

Hint: You can use the command button wizard to open a form and display
certain records as well.

HTH,
Josh




.
 
Joe,

I assumed [Acct #] was the name of the field, not the textbox. Your best
bet would be to keep the name property and controlsource property the same
for texboxes. This will avoid the confusion. It's also a good idea to
avoid using spaces or characters like #, & , %, Etc in your field or control
names. The nice part is you can refer to any if the fields in a form's
recordsource by field name regardless of the name of the control or
regardless of whether a control exists for that field.

Try this:
stLinkCriteria = "[Patient Number] = " & Me![Patient Number]

This should work whether you rename your controls or not, assuming that the
field Patient Number is in the recordsource of both forms.

HTH,
Josh

Joe said:
I understand the code, however, when I use the code you
just specified, I get a box popping up asking for me to
input an Acct #. I have tried different variations on the
specified fields, (ie - Acct #).

My names are as follows. The field ID is Patient Number
in the table. On both forms the control source is Patient
Number, bu ton form one, the nam eof hte text box is Acct
#, on the second form that I need the same patient info to
pop up on, the name of the text box is Text39. The
combination of htese things is confusing me and the
compiler apparently! thanks for all of your help and if
you have any more ideas let me know!
-----Original Message-----
Joe,

If the unique primary key for a patient is a field called [Acct #] then
simply add this line of code before the DoCmd.OpenForm line in each of the
command button click events on each form:

stLinkCriteria = "[Acct #] = " & Me![Acct #]

So the resulting code should look some thing like this:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "YourFormName"
stLinkCriteria = "[Acct #] = " & Me![Acct #]

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

If you still can't get this to work, then try creating new buttons using the
command button wizard and choosing 'Open the form and Find Specific Data to
Display' instead of 'Open the form and Display all records' This will allow
you to choose the correct fields to link by.

HTH,
Josh

Joe said:
I am trying to edit the code for this button n my forms
database. In the "PatientID" you refer to, would that be
the nam ein the properties field on the patient number box
I am trying to reference? I have several forms with a
command button structure that I nee dto edit code for each
of them. Each form has the patient ID 'name' in the
properties box different, so how do I go about coding each
button?

When I put the code in you told me and used "Acct #" in
plac eof Patient ID, a query box came up asking for me ot
input a record # (acct #). I just need the correct form
to pop up with the same patient info I was just working on
in one form to be displayed in the form I clicked on.
Thanks!
-----Original Message-----
Joe,

Try This:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormName"

stLinkCriteria = "[PatientID] = " & Me!
[PatientID] 'assuming PatientID
is a number

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

Assuming ButttonName is the name of the command button
and PatientID is the
Primary Key and is a number.

Hint: You can use the command button wizard to open a
form and display
certain records as well.

HTH,
Josh

I have a database built that has several forms with
buttons in each to link each other for easy
viewing/switching of the forms. Each page displays info
about a patient, however, with different fields. When I
select a certain patient on the first form and click to
another form, the same patient doesn't come up, the new
form just reverts to the patient in record one. what
code
do I use so that the same patient being viewed in the
current form comes up when I click on the button fo rthe
new form to display othe rinfo for te same patient?
Thanks!


.


.
 
I found that this code from the wizard works to display
the current recdord I am on in the other form when it
opens up.

stLinkCriteria = "[Patient Number]=" & "'" & Me![Acct #]
& "'"

However, fo rmy testing phase, I have 450 records, and it
only transfers the one that is displayed over to the new
form for editing info. How would I modify that code to
allow all of the records to be able to be displayed, but
the one I was just currently on in the first form to still
be 'active.'

Thanks!
-----Original Message-----
Joe,

I assumed [Acct #] was the name of the field, not the textbox. Your best
bet would be to keep the name property and controlsource property the same
for texboxes. This will avoid the confusion. It's also a good idea to
avoid using spaces or characters like #, & , %, Etc in your field or control
names. The nice part is you can refer to any if the fields in a form's
recordsource by field name regardless of the name of the control or
regardless of whether a control exists for that field.

Try this:
stLinkCriteria = "[Patient Number] = " & Me![Patient Number]

This should work whether you rename your controls or not, assuming that the
field Patient Number is in the recordsource of both forms.

HTH,
Josh

Joe said:
I understand the code, however, when I use the code you
just specified, I get a box popping up asking for me to
input an Acct #. I have tried different variations on the
specified fields, (ie - Acct #).

My names are as follows. The field ID is Patient Number
in the table. On both forms the control source is Patient
Number, bu ton form one, the nam eof hte text box is Acct
#, on the second form that I need the same patient info to
pop up on, the name of the text box is Text39. The
combination of htese things is confusing me and the
compiler apparently! thanks for all of your help and if
you have any more ideas let me know!
-----Original Message-----
Joe,

If the unique primary key for a patient is a field
called
[Acct #] then
simply add this line of code before the DoCmd.OpenForm line in each of the
command button click events on each form:

stLinkCriteria = "[Acct #] = " & Me![Acct #]

So the resulting code should look some thing like this:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "YourFormName"
stLinkCriteria = "[Acct #] = " & Me![Acct #]

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

If you still can't get this to work, then try creating new buttons using the
command button wizard and choosing 'Open the form and Find Specific Data to
Display' instead of 'Open the form and Display all records' This will allow
you to choose the correct fields to link by.

HTH,
Josh

I am trying to edit the code for this button n my forms
database. In the "PatientID" you refer to, would
that
be
the nam ein the properties field on the patient
number
box
I am trying to reference? I have several forms with a
command button structure that I nee dto edit code for each
of them. Each form has the patient ID 'name' in the
properties box different, so how do I go about coding each
button?

When I put the code in you told me and used "Acct #" in
plac eof Patient ID, a query box came up asking for
me
ot
input a record # (acct #). I just need the correct form
to pop up with the same patient info I was just
working
on
in one form to be displayed in the form I clicked on.
Thanks!
-----Original Message-----
Joe,

Try This:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormName"

stLinkCriteria = "[PatientID] = " & Me!
[PatientID] 'assuming PatientID
is a number

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

Assuming ButttonName is the name of the command button
and PatientID is the
Primary Key and is a number.

Hint: You can use the command button wizard to open a
form and display
certain records as well.

HTH,
Josh

I have a database built that has several forms with
buttons in each to link each other for easy
viewing/switching of the forms. Each page
displays
info
about a patient, however, with different fields. When I
select a certain patient on the first form and
click
to
another form, the same patient doesn't come up,
the
new
form just reverts to the patient in record one. what
code
do I use so that the same patient being viewed in the
current form comes up when I click on the button
fo
rthe
new form to display othe rinfo for te same patient?
Thanks!


.



.


.
 
Joe,

All of the records are still in the table, but the Where clause of the
OpenForm Methods applies a filter to the newly opened form so it6 will
display only the filtered record. You can display all if you remove the
filter using the remove filter toolbar button. To open the form and display
all records and then find the one you're looking for, you'll have to use DAO
code. While wizards and LinkCriteria are designed to be easier for
beginners, recordset code is a little more complicated, but here goes:

Private Sub ButtonName_Click()
On Error Goto Err_Sub

Dim rst As DAO.Recordset

stDocName = "YourFormName"
stLinkCriteria = stLinkCriteria = "[Patient Number]=" & "'" & Me![Acct
#] & "'"
DoCmd.OpenForm stDocName 'Do Not Supply Link Criteria Here

Set rst = Forms!YourFormName.RecordsetClone
rst.FindFirst stLinkCriteria 'Link Criteria goes here
If rst.EOF Then
MsgBox "Record not found"
Else
Me.Recordset.Bookmark = rst.Bookmark
End If

Exit_Sub:
On Error Resume Next
rst.close
Set rst = Nothing
Err_Sub:
MsgBox Err.Description
Resume Exit_Sub
End Sub

I very rarely find it necessary to use this method because I don't mind the
form opening with only a single record displaying. In fact, I think it's
better for db performance to use the filter method.

HTH,
Josh

Joe said:
I found that this code from the wizard works to display
the current recdord I am on in the other form when it
opens up.

stLinkCriteria = "[Patient Number]=" & "'" & Me![Acct #]
& "'"

However, fo rmy testing phase, I have 450 records, and it
only transfers the one that is displayed over to the new
form for editing info. How would I modify that code to
allow all of the records to be able to be displayed, but
the one I was just currently on in the first form to still
be 'active.'

Thanks!
-----Original Message-----
Joe,

I assumed [Acct #] was the name of the field, not the textbox. Your best
bet would be to keep the name property and controlsource property the same
for texboxes. This will avoid the confusion. It's also a good idea to
avoid using spaces or characters like #, & , %, Etc in your field or control
names. The nice part is you can refer to any if the fields in a form's
recordsource by field name regardless of the name of the control or
regardless of whether a control exists for that field.

Try this:
stLinkCriteria = "[Patient Number] = " & Me![Patient Number]

This should work whether you rename your controls or not, assuming that the
field Patient Number is in the recordsource of both forms.

HTH,
Josh

Joe said:
I understand the code, however, when I use the code you
just specified, I get a box popping up asking for me to
input an Acct #. I have tried different variations on the
specified fields, (ie - Acct #).

My names are as follows. The field ID is Patient Number
in the table. On both forms the control source is Patient
Number, bu ton form one, the nam eof hte text box is Acct
#, on the second form that I need the same patient info to
pop up on, the name of the text box is Text39. The
combination of htese things is confusing me and the
compiler apparently! thanks for all of your help and if
you have any more ideas let me know!

-----Original Message-----
Joe,

If the unique primary key for a patient is a field called
[Acct #] then
simply add this line of code before the DoCmd.OpenForm
line in each of the
command button click events on each form:

stLinkCriteria = "[Acct #] = " & Me![Acct #]

So the resulting code should look some thing like this:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "YourFormName"
stLinkCriteria = "[Acct #] = " & Me![Acct #]

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

If you still can't get this to work, then try creating
new buttons using the
command button wizard and choosing 'Open the form and
Find Specific Data to
Display' instead of 'Open the form and Display all
records' This will allow
you to choose the correct fields to link by.

HTH,
Josh

I am trying to edit the code for this button n my forms
database. In the "PatientID" you refer to, would that
be
the nam ein the properties field on the patient number
box
I am trying to reference? I have several forms with a
command button structure that I nee dto edit code for
each
of them. Each form has the patient ID 'name' in the
properties box different, so how do I go about coding
each
button?

When I put the code in you told me and used "Acct #" in
plac eof Patient ID, a query box came up asking for me
ot
input a record # (acct #). I just need the correct form
to pop up with the same patient info I was just working
on
in one form to be displayed in the form I clicked on.
Thanks!
-----Original Message-----
Joe,

Try This:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormName"

stLinkCriteria = "[PatientID] = " & Me!
[PatientID] 'assuming PatientID
is a number

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

Assuming ButttonName is the name of the command button
and PatientID is the
Primary Key and is a number.

Hint: You can use the command button wizard to open a
form and display
certain records as well.

HTH,
Josh

I have a database built that has several forms with
buttons in each to link each other for easy
viewing/switching of the forms. Each page displays
info
about a patient, however, with different fields.
When I
select a certain patient on the first form and click
to
another form, the same patient doesn't come up, the
new
form just reverts to the patient in record one. what
code
do I use so that the same patient being viewed in the
current form comes up when I click on the button fo
rthe
new form to display othe rinfo for te same patient?
Thanks!


.



.


.
 
Thanks for all of your help, but the compiler doesn't
recognized "rst As DAO.Recordset." And the linkcriteria
lines (the firs tones) are in red, but it can't get past
that first record set.

I tried using hte remove filter, it works, but then
reverts tot eh first record instead of staying on the
curent one accessed. i didn't think this would be so
complicated!

Thanks!
-----Original Message-----
Joe,

All of the records are still in the table, but the Where clause of the
OpenForm Methods applies a filter to the newly opened form so it6 will
display only the filtered record. You can display all if you remove the
filter using the remove filter toolbar button. To open the form and display
all records and then find the one you're looking for, you'll have to use DAO
code. While wizards and LinkCriteria are designed to be easier for
beginners, recordset code is a little more complicated, but here goes:

Private Sub ButtonName_Click()
On Error Goto Err_Sub

Dim rst As DAO.Recordset

stDocName = "YourFormName"
stLinkCriteria = stLinkCriteria = "[Patient Number]=" & "'" & Me![Acct
#] & "'"
DoCmd.OpenForm stDocName 'Do Not Supply Link Criteria Here

Set rst = Forms!YourFormName.RecordsetClone
rst.FindFirst stLinkCriteria 'Link Criteria goes here
If rst.EOF Then
MsgBox "Record not found"
Else
Me.Recordset.Bookmark = rst.Bookmark
End If

Exit_Sub:
On Error Resume Next
rst.close
Set rst = Nothing
Err_Sub:
MsgBox Err.Description
Resume Exit_Sub
End Sub

I very rarely find it necessary to use this method because I don't mind the
form opening with only a single record displaying. In fact, I think it's
better for db performance to use the filter method.

HTH,
Josh

Joe said:
I found that this code from the wizard works to display
the current recdord I am on in the other form when it
opens up.

stLinkCriteria = "[Patient Number]=" & "'" & Me![Acct #]
& "'"

However, fo rmy testing phase, I have 450 records, and it
only transfers the one that is displayed over to the new
form for editing info. How would I modify that code to
allow all of the records to be able to be displayed, but
the one I was just currently on in the first form to still
be 'active.'

Thanks!
-----Original Message-----
Joe,

I assumed [Acct #] was the name of the field, not the textbox. Your best
bet would be to keep the name property and
controlsource
property the same
for texboxes. This will avoid the confusion. It's
also
a good idea to
avoid using spaces or characters like #, & , %, Etc in your field or control
names. The nice part is you can refer to any if the fields in a form's
recordsource by field name regardless of the name of
the
control or
regardless of whether a control exists for that field.

Try this:
stLinkCriteria = "[Patient Number] = " & Me![Patient Number]

This should work whether you rename your controls or
not,
assuming that the
field Patient Number is in the recordsource of both forms.

HTH,
Josh

I understand the code, however, when I use the code you
just specified, I get a box popping up asking for me to
input an Acct #. I have tried different variations
on
the
specified fields, (ie - Acct #).

My names are as follows. The field ID is Patient Number
in the table. On both forms the control source is Patient
Number, bu ton form one, the nam eof hte text box is Acct
#, on the second form that I need the same patient
info
to
pop up on, the name of the text box is Text39. The
combination of htese things is confusing me and the
compiler apparently! thanks for all of your help and if
you have any more ideas let me know!

-----Original Message-----
Joe,

If the unique primary key for a patient is a field called
[Acct #] then
simply add this line of code before the DoCmd.OpenForm
line in each of the
command button click events on each form:

stLinkCriteria = "[Acct #] = " & Me![Acct #]

So the resulting code should look some thing like this:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "YourFormName"
stLinkCriteria = "[Acct #] = " & Me![Acct #]

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

If you still can't get this to work, then try creating
new buttons using the
command button wizard and choosing 'Open the form and
Find Specific Data to
Display' instead of 'Open the form and Display all
records' This will allow
you to choose the correct fields to link by.

HTH,
Josh

I am trying to edit the code for this button n my forms
database. In the "PatientID" you refer to, would that
be
the nam ein the properties field on the patient number
box
I am trying to reference? I have several forms
with
a
command button structure that I nee dto edit code for
each
of them. Each form has the patient ID 'name' in the
properties box different, so how do I go about coding
each
button?

When I put the code in you told me and used "Acct
#"
in
plac eof Patient ID, a query box came up asking
for
me
ot
input a record # (acct #). I just need the
correct
form
to pop up with the same patient info I was just working
on
in one form to be displayed in the form I clicked on.
Thanks!
-----Original Message-----
Joe,

Try This:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormName"

stLinkCriteria = "[PatientID] = " & Me!
[PatientID] 'assuming PatientID
is a number

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

Assuming ButttonName is the name of the command button
and PatientID is the
Primary Key and is a number.

Hint: You can use the command button wizard to open a
form and display
certain records as well.

HTH,
Josh

I have a database built that has several forms with
buttons in each to link each other for easy
viewing/switching of the forms. Each page displays
info
about a patient, however, with different fields.
When I
select a certain patient on the first form and click
to
another form, the same patient doesn't come up, the
new
form just reverts to the patient in record one. what
code
do I use so that the same patient being viewed
in
the
current form comes up when I click on the
button
fo
rthe
new form to display othe rinfo for te same patient?
Thanks!


.



.



.


.
 
Joe,

The LinkCriteria Line is my mistake change it to this:
stLinkCriteria = "[Patient Number]= " & "'" & Me![Acct #] & "'"

You need to add a reference to DAO object library in the VBA editor like
this:
Open VBA Editor
Choose Tools | References
Scroll down the list until you find 'Microsoft DAO 3.6 Object Library'
Check the box next to it in the list
Click Ok
Choose Debug | Compile DatabaseName

Can I ask why you need to display all the records instead of just the one
you are interested in editing?

HTH,
Josh

Joe said:
Thanks for all of your help, but the compiler doesn't
recognized "rst As DAO.Recordset." And the linkcriteria
lines (the firs tones) are in red, but it can't get past
that first record set.

I tried using hte remove filter, it works, but then
reverts tot eh first record instead of staying on the
curent one accessed. i didn't think this would be so
complicated!

Thanks!
-----Original Message-----
Joe,

All of the records are still in the table, but the Where clause of the
OpenForm Methods applies a filter to the newly opened form so it6 will
display only the filtered record. You can display all if you remove the
filter using the remove filter toolbar button. To open the form and display
all records and then find the one you're looking for, you'll have to use DAO
code. While wizards and LinkCriteria are designed to be easier for
beginners, recordset code is a little more complicated, but here goes:

Private Sub ButtonName_Click()
On Error Goto Err_Sub

Dim rst As DAO.Recordset

stDocName = "YourFormName"
stLinkCriteria = stLinkCriteria = "[Patient Number]=" & "'" & Me![Acct
#] & "'"
DoCmd.OpenForm stDocName 'Do Not Supply Link Criteria Here

Set rst = Forms!YourFormName.RecordsetClone
rst.FindFirst stLinkCriteria 'Link Criteria goes here
If rst.EOF Then
MsgBox "Record not found"
Else
Me.Recordset.Bookmark = rst.Bookmark
End If

Exit_Sub:
On Error Resume Next
rst.close
Set rst = Nothing
Err_Sub:
MsgBox Err.Description
Resume Exit_Sub
End Sub

I very rarely find it necessary to use this method because I don't mind the
form opening with only a single record displaying. In fact, I think it's
better for db performance to use the filter method.

HTH,
Josh

Joe said:
I found that this code from the wizard works to display
the current recdord I am on in the other form when it
opens up.

stLinkCriteria = "[Patient Number]=" & "'" & Me![Acct #]
& "'"

However, fo rmy testing phase, I have 450 records, and it
only transfers the one that is displayed over to the new
form for editing info. How would I modify that code to
allow all of the records to be able to be displayed, but
the one I was just currently on in the first form to still
be 'active.'

Thanks!

-----Original Message-----
Joe,

I assumed [Acct #] was the name of the field, not the
textbox. Your best
bet would be to keep the name property and controlsource
property the same
for texboxes. This will avoid the confusion. It's also
a good idea to
avoid using spaces or characters like #, & , %, Etc in
your field or control
names. The nice part is you can refer to any if the
fields in a form's
recordsource by field name regardless of the name of the
control or
regardless of whether a control exists for that field.

Try this:
stLinkCriteria = "[Patient Number] = " & Me![Patient
Number]

This should work whether you rename your controls or not,
assuming that the
field Patient Number is in the recordsource of both forms.

HTH,
Josh

I understand the code, however, when I use the code you
just specified, I get a box popping up asking for me to
input an Acct #. I have tried different variations on
the
specified fields, (ie - Acct #).

My names are as follows. The field ID is Patient Number
in the table. On both forms the control source is
Patient
Number, bu ton form one, the nam eof hte text box is
Acct
#, on the second form that I need the same patient info
to
pop up on, the name of the text box is Text39. The
combination of htese things is confusing me and the
compiler apparently! thanks for all of your help and if
you have any more ideas let me know!

-----Original Message-----
Joe,

If the unique primary key for a patient is a field
called
[Acct #] then
simply add this line of code before the DoCmd.OpenForm
line in each of the
command button click events on each form:

stLinkCriteria = "[Acct #] = " & Me![Acct #]

So the resulting code should look some thing like this:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "YourFormName"
stLinkCriteria = "[Acct #] = " & Me![Acct #]

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

If you still can't get this to work, then try creating
new buttons using the
command button wizard and choosing 'Open the form and
Find Specific Data to
Display' instead of 'Open the form and Display all
records' This will allow
you to choose the correct fields to link by.

HTH,
Josh

I am trying to edit the code for this button n my
forms
database. In the "PatientID" you refer to, would
that
be
the nam ein the properties field on the patient
number
box
I am trying to reference? I have several forms with
a
command button structure that I nee dto edit code for
each
of them. Each form has the patient ID 'name' in the
properties box different, so how do I go about coding
each
button?

When I put the code in you told me and used "Acct #"
in
plac eof Patient ID, a query box came up asking for
me
ot
input a record # (acct #). I just need the correct
form
to pop up with the same patient info I was just
working
on
in one form to be displayed in the form I clicked on.
Thanks!
-----Original Message-----
Joe,

Try This:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormName"

stLinkCriteria = "[PatientID] = " & Me!
[PatientID] 'assuming PatientID
is a number

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

Assuming ButttonName is the name of the command
button
and PatientID is the
Primary Key and is a number.

Hint: You can use the command button wizard to
open a
form and display
certain records as well.

HTH,
Josh

I have a database built that has several forms
with
buttons in each to link each other for easy
viewing/switching of the forms. Each page
displays
info
about a patient, however, with different fields.
When I
select a certain patient on the first form and
click
to
another form, the same patient doesn't come up,
the
new
form just reverts to the patient in record one.
what
code
do I use so that the same patient being viewed in
the
current form comes up when I click on the button
fo
rthe
new form to display othe rinfo for te same
patient?
Thanks!


.



.



.


.
 
I tried that code again, it can't seem to find the nam eof
my form in the recordsetclone. But I found another way to
do it where it limits the records deisplayed like you said
before, that'll have to do. I needed lal the records
accessible because this is a patient database, so no
matter what form (database page) I was on, I have
next/previous record tabs to scroll through. But I wanted
whatever current record I was on in any of those forms to
be displayed on the nexted open form to edit different
info on that patient. This should work, it is just a
roundabout way. Thanks for all of your help!
-----Original Message-----
Joe,

The LinkCriteria Line is my mistake change it to this:
stLinkCriteria = "[Patient Number]= " & "'" & Me![Acct #] & "'"

You need to add a reference to DAO object library in the VBA editor like
this:
Open VBA Editor
Choose Tools | References
Scroll down the list until you find 'Microsoft DAO 3.6 Object Library'
Check the box next to it in the list
Click Ok
Choose Debug | Compile DatabaseName

Can I ask why you need to display all the records instead of just the one
you are interested in editing?

HTH,
Josh

Joe said:
Thanks for all of your help, but the compiler doesn't
recognized "rst As DAO.Recordset." And the linkcriteria
lines (the firs tones) are in red, but it can't get past
that first record set.

I tried using hte remove filter, it works, but then
reverts tot eh first record instead of staying on the
curent one accessed. i didn't think this would be so
complicated!

Thanks!
-----Original Message-----
Joe,

All of the records are still in the table, but the
Where
clause of the
OpenForm Methods applies a filter to the newly opened form so it6 will
display only the filtered record. You can display all
if
you remove the
filter using the remove filter toolbar button. To open the form and display
all records and then find the one you're looking for, you'll have to use DAO
code. While wizards and LinkCriteria are designed to
be
easier for
beginners, recordset code is a little more complicated, but here goes:

Private Sub ButtonName_Click()
On Error Goto Err_Sub

Dim rst As DAO.Recordset

stDocName = "YourFormName"
stLinkCriteria = stLinkCriteria = "[Patient Number]
="
& "'" & Me![Acct
#] & "'"
DoCmd.OpenForm stDocName 'Do Not Supply Link Criteria Here

Set rst = Forms!YourFormName.RecordsetClone
rst.FindFirst stLinkCriteria 'Link Criteria goes here
If rst.EOF Then
MsgBox "Record not found"
Else
Me.Recordset.Bookmark = rst.Bookmark
End If

Exit_Sub:
On Error Resume Next
rst.close
Set rst = Nothing
Err_Sub:
MsgBox Err.Description
Resume Exit_Sub
End Sub

I very rarely find it necessary to use this method because I don't mind the
form opening with only a single record displaying. In fact, I think it's
better for db performance to use the filter method.

HTH,
Josh

I found that this code from the wizard works to display
the current recdord I am on in the other form when it
opens up.

stLinkCriteria = "[Patient Number]=" & "'" & Me! [Acct #]
& "'"

However, fo rmy testing phase, I have 450 records,
and
it
only transfers the one that is displayed over to the new
form for editing info. How would I modify that code to
allow all of the records to be able to be displayed, but
the one I was just currently on in the first form to still
be 'active.'

Thanks!

-----Original Message-----
Joe,

I assumed [Acct #] was the name of the field, not the
textbox. Your best
bet would be to keep the name property and controlsource
property the same
for texboxes. This will avoid the confusion. It's also
a good idea to
avoid using spaces or characters like #, & , %, Etc in
your field or control
names. The nice part is you can refer to any if the
fields in a form's
recordsource by field name regardless of the name of the
control or
regardless of whether a control exists for that field.

Try this:
stLinkCriteria = "[Patient Number] = " & Me![Patient
Number]

This should work whether you rename your controls or not,
assuming that the
field Patient Number is in the recordsource of both forms.

HTH,
Josh

I understand the code, however, when I use the
code
you
just specified, I get a box popping up asking for
me
to
input an Acct #. I have tried different
variations
on
the
specified fields, (ie - Acct #).

My names are as follows. The field ID is Patient Number
in the table. On both forms the control source is
Patient
Number, bu ton form one, the nam eof hte text box is
Acct
#, on the second form that I need the same patient info
to
pop up on, the name of the text box is Text39. The
combination of htese things is confusing me and the
compiler apparently! thanks for all of your help and if
you have any more ideas let me know!

-----Original Message-----
Joe,

If the unique primary key for a patient is a field
called
[Acct #] then
simply add this line of code before the DoCmd.OpenForm
line in each of the
command button click events on each form:

stLinkCriteria = "[Acct #] = " & Me![Acct #]

So the resulting code should look some thing like this:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "YourFormName"
stLinkCriteria = "[Acct #] = " & Me![Acct #]

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

If you still can't get this to work, then try creating
new buttons using the
command button wizard and choosing 'Open the form and
Find Specific Data to
Display' instead of 'Open the form and Display all
records' This will allow
you to choose the correct fields to link by.

HTH,
Josh

I am trying to edit the code for this button n my
forms
database. In the "PatientID" you refer to, would
that
be
the nam ein the properties field on the patient
number
box
I am trying to reference? I have several forms with
a
command button structure that I nee dto edit
code
for
each
of them. Each form has the patient ID 'name'
in
the
properties box different, so how do I go about coding
each
button?

When I put the code in you told me and
used "Acct
#"
in
plac eof Patient ID, a query box came up asking for
me
ot
input a record # (acct #). I just need the correct
form
to pop up with the same patient info I was just
working
on
in one form to be displayed in the form I
clicked
on.
Thanks!
-----Original Message-----
Joe,

Try This:

Private Sub ButtonName_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormName"

stLinkCriteria = "[PatientID] = " & Me!
[PatientID] 'assuming PatientID
is a number

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

Assuming ButttonName is the name of the command
button
and PatientID is the
Primary Key and is a number.

Hint: You can use the command button wizard to
open a
form and display
certain records as well.

HTH,
Josh

I have a database built that has several forms
with
buttons in each to link each other for easy
viewing/switching of the forms. Each page
displays
info
about a patient, however, with different fields.
When I
select a certain patient on the first form and
click
to
another form, the same patient doesn't come up,
the
new
form just reverts to the patient in record one.
what
code
do I use so that the same patient being
viewed
in
the
current form comes up when I click on the button
fo
rthe
new form to display othe rinfo for te same
patient?
Thanks!


.



.



.



.


.
 
Back
Top