open a new form in Subform

  • Thread starter accessuser via AccessMonster.com
  • Start date
A

accessuser via AccessMonster.com

My primary key for the main form is "EmpID" which links to the subform. The
subform has "CourseID", and some other information. The form will show each
employee with all of their courses information in the subform. I have a
command button called "Detail" next to the courseID. I want users to be able
to click on the "Detail" and open up a new form with the Cost Information for
that one particular CourseID information. the following is the code I got
from other site, but dont know what they mean. It does help me open up the
form but not finding the match cost for the courseID

Private Sub cmdDetails_Click()
Dim frm As Form
If Not IsNull(Me!CourseID) Then

gstrWherebook = "[CourseID] = """ & Me!CourseID & """"
DoCmd.OpenForm FormName:="frmCost", WhereCondition:=gstrWherebook

Set frm = Forms!FrmCost

End If
End Sub

What is "gstrWherebook" and "WhereCondition=gstrWherebook mean? What should
I replace that for my database?

Thank you very much!!!
 
M

Marshall Barton

accessuser said:
My primary key for the main form is "EmpID" which links to the subform. The
subform has "CourseID", and some other information. The form will show each
employee with all of their courses information in the subform. I have a
command button called "Detail" next to the courseID. I want users to be able
to click on the "Detail" and open up a new form with the Cost Information for
that one particular CourseID information. the following is the code I got
from other site, but dont know what they mean. It does help me open up the
form but not finding the match cost for the courseID

Private Sub cmdDetails_Click()
Dim frm As Form
If Not IsNull(Me!CourseID) Then

gstrWherebook = "[CourseID] = """ & Me!CourseID & """"
DoCmd.OpenForm FormName:="frmCost", WhereCondition:=gstrWherebook

Set frm = Forms!FrmCost

End If
End Sub

What is "gstrWherebook" and "WhereCondition=gstrWherebook mean? What should
I replace that for my database?


The name gstrWherebook implies it is a global string
variable. Out of context, there is no reason for it to be
global, so just declare it in the Click procedure.

You left out the : in the other part of your question.
WhereCondition:=gstrWherebook
is a "named" argument to the OpenForm method (see VBA Help
for details). If you don't like using a named argument, use
the appropriate number of commas instead.

In the above procedure, there is no reason to have or set
the from object so you can remove that.

Private Sub cmdDetails_Click()
Dim strWhere As String
If Not IsNull(Me!CourseID) Then
strWhere = "CourseID = """ & Me!CourseID & """"
DoCmd.OpenForm "frmCost", WhereCondition:=strWhere
End If
End Sub

The above code assumes that the CourseID field in the table
is a Text field. If it is a numeric type field, it should
be:
strWhere = "CourseID = " & Me!CourseID
DoCmd.OpenForm "frmCost", WhereCondition:=strWhere
 
A

accessuser via AccessMonster.com

Thank you very much Marshall. It works!!!!!!!!!!!!!!!

Marshall said:
My primary key for the main form is "EmpID" which links to the subform. The
subform has "CourseID", and some other information. The form will show each
[quoted text clipped - 19 lines]
What is "gstrWherebook" and "WhereCondition=gstrWherebook mean? What should
I replace that for my database?

The name gstrWherebook implies it is a global string
variable. Out of context, there is no reason for it to be
global, so just declare it in the Click procedure.

You left out the : in the other part of your question.
WhereCondition:=gstrWherebook
is a "named" argument to the OpenForm method (see VBA Help
for details). If you don't like using a named argument, use
the appropriate number of commas instead.

In the above procedure, there is no reason to have or set
the from object so you can remove that.

Private Sub cmdDetails_Click()
Dim strWhere As String
If Not IsNull(Me!CourseID) Then
strWhere = "CourseID = """ & Me!CourseID & """"
DoCmd.OpenForm "frmCost", WhereCondition:=strWhere
End If
End Sub

The above code assumes that the CourseID field in the table
is a Text field. If it is a numeric type field, it should
be:
strWhere = "CourseID = " & Me!CourseID
DoCmd.OpenForm "frmCost", WhereCondition:=strWhere
 

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