Open form that matches criteria from previous form

G

Guest

I have a form that is connected by ProjectID. Under Projects, we have tasks.
On this form, there is a command button that allows you to look at the tasks
that are under the specific project. On this subform, is a command button to
add another task to that particular project. I can get the form to come up
as a blank form
but not with the ProjectID that it is to be added to. The user will not have
the option to choose which ProjectID to add it to, I want it to be automatic
from the previous form. The code is as follows:

Dim stLinkCriteria As String

DoCmd.GoToRecord acForm, Me.Name, acNewRec
stLinkCriteria = "[ProjectID]=" & Me!ProjectID
 
M

Marshall Barton

Diane said:
I have a form that is connected by ProjectID. Under Projects, we have tasks.
On this form, there is a command button that allows you to look at the tasks
that are under the specific project. On this subform, is a command button to
add another task to that particular project. I can get the form to come up
as a blank form
but not with the ProjectID that it is to be added to. The user will not have
the option to choose which ProjectID to add it to, I want it to be automatic
from the previous form. The code is as follows:

Dim stLinkCriteria As String

DoCmd.GoToRecord acForm, Me.Name, acNewRec
stLinkCriteria = "[ProjectID]=" & Me!ProjectID


That is not going to get the ProjectID to the subform. The
stLinkCriteria would be used in the OpenForm's
WhereCondition argument to select existing tasks for that
project when you open a separate form, not to tell a subform
to fill in a value.

None of this is needed since the tasks subform uses the Link
Master/Child properties to make the subform display only the
tasks for the main form's current record without any need
for you do do anything else.

Since all that is automatic, I suspect that I was unable to
grasp your arrangement of form and subform, possibly because
you are using some words in an inappropriate way.
 
G

Guest

Sorry Marshall,
I will attempt to explain what is happening. I have a project form, on
the form I click a command button that opens the tasks that are associated to
that project. On that Task form, I have a command button that allows the
user to add a task to that particular project, but when the form comes up, it
comes up with all fields blank, especially the ProjectID, which means the
information added will not be associated to the current project. I need the
information that will be added to go to directly to the current Project. did
that help any?? If not, please let me know.

Marshall Barton said:
Diane said:
I have a form that is connected by ProjectID. Under Projects, we have tasks.
On this form, there is a command button that allows you to look at the tasks
that are under the specific project. On this subform, is a command button to
add another task to that particular project. I can get the form to come up
as a blank form
but not with the ProjectID that it is to be added to. The user will not have
the option to choose which ProjectID to add it to, I want it to be automatic
from the previous form. The code is as follows:

Dim stLinkCriteria As String

DoCmd.GoToRecord acForm, Me.Name, acNewRec
stLinkCriteria = "[ProjectID]=" & Me!ProjectID


That is not going to get the ProjectID to the subform. The
stLinkCriteria would be used in the OpenForm's
WhereCondition argument to select existing tasks for that
project when you open a separate form, not to tell a subform
to fill in a value.

None of this is needed since the tasks subform uses the Link
Master/Child properties to make the subform display only the
tasks for the main form's current record without any need
for you do do anything else.

Since all that is automatic, I suspect that I was unable to
grasp your arrangement of form and subform, possibly because
you are using some words in an inappropriate way.
 
M

Marshall Barton

Ahh, it is a separate form, not a subform. If the form is
not already open, use this kind of code to open it:

Dim stLinkCriteria As String
stLinkCriteria = "[ProjectID]=" & Me!ProjectID
DoCmd.OpenForm "Tasks", _
WhereCondition:= stLinkCriteria, _
OpenArgs:= ProjectID

Then in the tasks form's Load event, use this code:

If Not IsNull(Me.OpenArgs) Then
Me.txtProjectID.DefaultValue = Me.OpenArgs
DoCmd.GoToRecord acForm, Me.Name, acNewRec
End If
--
Marsh
MVP [MS Access]

I will attempt to explain what is happening. I have a project form, on
the form I click a command button that opens the tasks that are associated to
that project. On that Task form, I have a command button that allows the
user to add a task to that particular project, but when the form comes up, it
comes up with all fields blank, especially the ProjectID, which means the
information added will not be associated to the current project. I need the
information that will be added to go to directly to the current Project. did
that help any?? If not, please let me know.

Marshall Barton said:
Diane said:
I have a form that is connected by ProjectID. Under Projects, we have tasks.
On this form, there is a command button that allows you to look at the tasks
that are under the specific project. On this subform, is a command button to
add another task to that particular project. I can get the form to come up
as a blank form
but not with the ProjectID that it is to be added to. The user will not have
the option to choose which ProjectID to add it to, I want it to be automatic
from the previous form. The code is as follows:

Dim stLinkCriteria As String

DoCmd.GoToRecord acForm, Me.Name, acNewRec
stLinkCriteria = "[ProjectID]=" & Me!ProjectID


That is not going to get the ProjectID to the subform. The
stLinkCriteria would be used in the OpenForm's
WhereCondition argument to select existing tasks for that
project when you open a separate form, not to tell a subform
to fill in a value.

None of this is needed since the tasks subform uses the Link
Master/Child properties to make the subform display only the
tasks for the main form's current record without any need
for you do do anything else.

Since all that is automatic, I suspect that I was unable to
grasp your arrangement of form and subform, possibly because
you are using some words in an inappropriate way.
 
G

Guest

Marshall,
thank you for your help but on the statement "Me.txtProjectID", I received
an error message "Method or data member not found". I thought there might be
one because as I was typing, there was not a selection for "txt" after I
typed the period. I am looking for a solution.

Marshall Barton said:
Ahh, it is a separate form, not a subform. If the form is
not already open, use this kind of code to open it:

Dim stLinkCriteria As String
stLinkCriteria = "[ProjectID]=" & Me!ProjectID
DoCmd.OpenForm "Tasks", _
WhereCondition:= stLinkCriteria, _
OpenArgs:= ProjectID

Then in the tasks form's Load event, use this code:

If Not IsNull(Me.OpenArgs) Then
Me.txtProjectID.DefaultValue = Me.OpenArgs
DoCmd.GoToRecord acForm, Me.Name, acNewRec
End If
--
Marsh
MVP [MS Access]

I will attempt to explain what is happening. I have a project form, on
the form I click a command button that opens the tasks that are associated to
that project. On that Task form, I have a command button that allows the
user to add a task to that particular project, but when the form comes up, it
comes up with all fields blank, especially the ProjectID, which means the
information added will not be associated to the current project. I need the
information that will be added to go to directly to the current Project. did
that help any?? If not, please let me know.

Marshall Barton said:
Diane wrote:

I have a form that is connected by ProjectID. Under Projects, we have tasks.
On this form, there is a command button that allows you to look at the tasks
that are under the specific project. On this subform, is a command button to
add another task to that particular project. I can get the form to come up
as a blank form
but not with the ProjectID that it is to be added to. The user will not have
the option to choose which ProjectID to add it to, I want it to be automatic
from the previous form. The code is as follows:

Dim stLinkCriteria As String

DoCmd.GoToRecord acForm, Me.Name, acNewRec
stLinkCriteria = "[ProjectID]=" & Me!ProjectID


That is not going to get the ProjectID to the subform. The
stLinkCriteria would be used in the OpenForm's
WhereCondition argument to select existing tasks for that
project when you open a separate form, not to tell a subform
to fill in a value.

None of this is needed since the tasks subform uses the Link
Master/Child properties to make the subform display only the
tasks for the main form's current record without any need
for you do do anything else.

Since all that is automatic, I suspect that I was unable to
grasp your arrangement of form and subform, possibly because
you are using some words in an inappropriate way.
 
G

Guest

Marshall,
I figured out what needed to be done and it works beautifully!!!! I just
needed to change "txtProjectID" to "ProjectID. Thank you so very much for
your help and you guys are the BEST!!! This discussion forum is an excellent
tool.

Marshall Barton said:
Ahh, it is a separate form, not a subform. If the form is
not already open, use this kind of code to open it:

Dim stLinkCriteria As String
stLinkCriteria = "[ProjectID]=" & Me!ProjectID
DoCmd.OpenForm "Tasks", _
WhereCondition:= stLinkCriteria, _
OpenArgs:= ProjectID

Then in the tasks form's Load event, use this code:

If Not IsNull(Me.OpenArgs) Then
Me.txtProjectID.DefaultValue = Me.OpenArgs
DoCmd.GoToRecord acForm, Me.Name, acNewRec
End If
--
Marsh
MVP [MS Access]

I will attempt to explain what is happening. I have a project form, on
the form I click a command button that opens the tasks that are associated to
that project. On that Task form, I have a command button that allows the
user to add a task to that particular project, but when the form comes up, it
comes up with all fields blank, especially the ProjectID, which means the
information added will not be associated to the current project. I need the
information that will be added to go to directly to the current Project. did
that help any?? If not, please let me know.

Marshall Barton said:
Diane wrote:

I have a form that is connected by ProjectID. Under Projects, we have tasks.
On this form, there is a command button that allows you to look at the tasks
that are under the specific project. On this subform, is a command button to
add another task to that particular project. I can get the form to come up
as a blank form
but not with the ProjectID that it is to be added to. The user will not have
the option to choose which ProjectID to add it to, I want it to be automatic
from the previous form. The code is as follows:

Dim stLinkCriteria As String

DoCmd.GoToRecord acForm, Me.Name, acNewRec
stLinkCriteria = "[ProjectID]=" & Me!ProjectID


That is not going to get the ProjectID to the subform. The
stLinkCriteria would be used in the OpenForm's
WhereCondition argument to select existing tasks for that
project when you open a separate form, not to tell a subform
to fill in a value.

None of this is needed since the tasks subform uses the Link
Master/Child properties to make the subform display only the
tasks for the main form's current record without any need
for you do do anything else.

Since all that is automatic, I suspect that I was unable to
grasp your arrangement of form and subform, possibly because
you are using some words in an inappropriate way.
 
M

Marshall Barton

Sorry about the confusion. I always rename controls that I
refer to in expressions or VBA code by prefixing the
control's bound field name with a three letter abbreviation
of the control's type (txt - text box, cbo - combo box,
etc). This prevents any confusion about whether I'm
referring to a control on the form/report or a field in the
record source table/query. All I was trying to indicate by
using txtProjectID was that you should use the name of the
text box bound to the ProjectID field, but you wouldn't know
that unless you used a similar naming convention.
--
Marsh
MVP [MS Access]

Marshall,
I figured out what needed to be done and it works beautifully!!!! I just
needed to change "txtProjectID" to "ProjectID. Thank you so very much for
your help and you guys are the BEST!!! This discussion forum is an excellent
tool.

Marshall Barton said:
Ahh, it is a separate form, not a subform. If the form is
not already open, use this kind of code to open it:

Dim stLinkCriteria As String
stLinkCriteria = "[ProjectID]=" & Me!ProjectID
DoCmd.OpenForm "Tasks", _
WhereCondition:= stLinkCriteria, _
OpenArgs:= ProjectID

Then in the tasks form's Load event, use this code:

If Not IsNull(Me.OpenArgs) Then
Me.txtProjectID.DefaultValue = Me.OpenArgs
DoCmd.GoToRecord acForm, Me.Name, acNewRec
End If

I will attempt to explain what is happening. I have a project form, on
the form I click a command button that opens the tasks that are associated to
that project. On that Task form, I have a command button that allows the
user to add a task to that particular project, but when the form comes up, it
comes up with all fields blank, especially the ProjectID, which means the
information added will not be associated to the current project. I need the
information that will be added to go to directly to the current Project. did
that help any?? If not, please let me know.

:

Diane wrote:

I have a form that is connected by ProjectID. Under Projects, we have tasks.
On this form, there is a command button that allows you to look at the tasks
that are under the specific project. On this subform, is a command button to
add another task to that particular project. I can get the form to come up
as a blank form
but not with the ProjectID that it is to be added to. The user will not have
the option to choose which ProjectID to add it to, I want it to be automatic
from the previous form. The code is as follows:

Dim stLinkCriteria As String

DoCmd.GoToRecord acForm, Me.Name, acNewRec
stLinkCriteria = "[ProjectID]=" & Me!ProjectID


That is not going to get the ProjectID to the subform. The
stLinkCriteria would be used in the OpenForm's
WhereCondition argument to select existing tasks for that
project when you open a separate form, not to tell a subform
to fill in a value.

None of this is needed since the tasks subform uses the Link
Master/Child properties to make the subform display only the
tasks for the main form's current record without any need
for you do do anything else.

Since all that is automatic, I suspect that I was unable to
grasp your arrangement of form and subform, possibly because
you are using some words in an inappropriate way.
 
G

Guest

thank you very much Marshall. Have a great day.

Marshall Barton said:
Sorry about the confusion. I always rename controls that I
refer to in expressions or VBA code by prefixing the
control's bound field name with a three letter abbreviation
of the control's type (txt - text box, cbo - combo box,
etc). This prevents any confusion about whether I'm
referring to a control on the form/report or a field in the
record source table/query. All I was trying to indicate by
using txtProjectID was that you should use the name of the
text box bound to the ProjectID field, but you wouldn't know
that unless you used a similar naming convention.
--
Marsh
MVP [MS Access]

Marshall,
I figured out what needed to be done and it works beautifully!!!! I just
needed to change "txtProjectID" to "ProjectID. Thank you so very much for
your help and you guys are the BEST!!! This discussion forum is an excellent
tool.

Marshall Barton said:
Ahh, it is a separate form, not a subform. If the form is
not already open, use this kind of code to open it:

Dim stLinkCriteria As String
stLinkCriteria = "[ProjectID]=" & Me!ProjectID
DoCmd.OpenForm "Tasks", _
WhereCondition:= stLinkCriteria, _
OpenArgs:= ProjectID

Then in the tasks form's Load event, use this code:

If Not IsNull(Me.OpenArgs) Then
Me.txtProjectID.DefaultValue = Me.OpenArgs
DoCmd.GoToRecord acForm, Me.Name, acNewRec
End If


Diane wrote:
I will attempt to explain what is happening. I have a project form, on
the form I click a command button that opens the tasks that are associated to
that project. On that Task form, I have a command button that allows the
user to add a task to that particular project, but when the form comes up, it
comes up with all fields blank, especially the ProjectID, which means the
information added will not be associated to the current project. I need the
information that will be added to go to directly to the current Project. did
that help any?? If not, please let me know.

:

Diane wrote:

I have a form that is connected by ProjectID. Under Projects, we have tasks.
On this form, there is a command button that allows you to look at the tasks
that are under the specific project. On this subform, is a command button to
add another task to that particular project. I can get the form to come up
as a blank form
but not with the ProjectID that it is to be added to. The user will not have
the option to choose which ProjectID to add it to, I want it to be automatic
from the previous form. The code is as follows:

Dim stLinkCriteria As String

DoCmd.GoToRecord acForm, Me.Name, acNewRec
stLinkCriteria = "[ProjectID]=" & Me!ProjectID


That is not going to get the ProjectID to the subform. The
stLinkCriteria would be used in the OpenForm's
WhereCondition argument to select existing tasks for that
project when you open a separate form, not to tell a subform
to fill in a value.

None of this is needed since the tasks subform uses the Link
Master/Child properties to make the subform display only the
tasks for the main form's current record without any need
for you do do anything else.

Since all that is automatic, I suspect that I was unable to
grasp your arrangement of form and subform, possibly because
you are using some words in an inappropriate way.
 

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