Opening form to specific record

J

Jerry Anderson

The following code is automatically generated by the "open Form" command
button. Is there a way to modify the code so that an additional parameter
[CostCenter] can be used in conjunction with the variable [EventName]?

If ActualProjected.Value = "Projected" Then
stDocName = "ProjectedEventDetails"
stLinkCriteria = "[EventName]=" & "'" & Me![SelectEvent] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
stDocName = "ActualEventDetails"
stLinkCriteria = "[EventName]=" & "'" & Me![SelectEvent] & "'"
Me.Visible = False

DoCmd.OpenForm stDocName, , , stLinkCriteria

End If
 
F

fredg

The following code is automatically generated by the "open Form" command
button. Is there a way to modify the code so that an additional parameter
[CostCenter] can be used in conjunction with the variable [EventName]?

If ActualProjected.Value = "Projected" Then
stDocName = "ProjectedEventDetails"
stLinkCriteria = "[EventName]=" & "'" & Me![SelectEvent] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
stDocName = "ActualEventDetails"
stLinkCriteria = "[EventName]=" & "'" & Me![SelectEvent] & "'"
Me.Visible = False

DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

This part is not necessary ... =" & "'" & Me.[.....] etc.
See below.

What is the datatype of the [CostCenter] field?
Is it a field shown on the Form?
Let's assume [CostCenter] is shown on the form and it is a text
datatype.

stLinkCriteria = "[EventName]= '"& Me![SelectEvent] & "' AND
[CostCenter] = '" & Me.[CostCenter] & "'"

For clarity, the quotes are as follows:
"[EventName]= ' " & Me![SelectEvent] & " ' AND [CostCenter] = ' " &
Me.[CostCenter] & " ' "
 
J

John W. Vinson

The following code is automatically generated by the "open Form" command
button. Is there a way to modify the code so that an additional parameter
[CostCenter] can be used in conjunction with the variable [EventName]?

If ActualProjected.Value = "Projected" Then
stDocName = "ProjectedEventDetails"
stLinkCriteria = "[EventName]=" & "'" & Me![SelectEvent] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
stDocName = "ActualEventDetails"
stLinkCriteria = "[EventName]=" & "'" & Me![SelectEvent] & "'"
Me.Visible = False

DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

Sure. stLinkCriteria needs to be a text string which contains a valid SQL
query WHERE clause without the WHERE, using AND, OR or any other valid SQL
operators. You don't say how CostCenter comes into the query, but at a guess
you could do something like

stLinkCriteria = "[EventName]=""" & Me![SelectEvent] _
& """ AND [CostCenter] = """ & Me![CostCenter] & """"

assuming that both fields are of Text type.
 

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