stLinkCriteria - Multiple criteria

R

Rick

Greetings,

I have the following code and I get a "The OpenForm action was
cancelled" message.

Private Sub btnThisWeeksGames_Click()

On Error GoTo Err_btnThisWeeksGames_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmGames"

stLinkCriteria = "[Season]='" & Me![cboSeasonID] & "' AND [Week]='"
& Me![cboWeek] & "'"
Debug.Print stLinkCriteria
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_btnThisWeeksGames_Click:
Exit Sub

Err_btnThisWeeksGames_Click:
MsgBox Err.Description
Resume Exit_btnThisWeeksGames_Click

End Sub


The Debug.Print statement yields [Season]='2005/2006' AND [Week]='9'


If I change it to stLinkCriteria = "[Season]='" & Me![cboSeasonID] &
"'"
it works just fine.

Please help a dumb Texan.
 
F

fredg

Greetings,

I have the following code and I get a "The OpenForm action was
cancelled" message.

Private Sub btnThisWeeksGames_Click()

On Error GoTo Err_btnThisWeeksGames_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmGames"

stLinkCriteria = "[Season]='" & Me![cboSeasonID] & "' AND [Week]='"
& Me![cboWeek] & "'"
Debug.Print stLinkCriteria
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_btnThisWeeksGames_Click:
Exit Sub

Err_btnThisWeeksGames_Click:
MsgBox Err.Description
Resume Exit_btnThisWeeksGames_Click

End Sub

The Debug.Print statement yields [Season]='2005/2006' AND [Week]='9'

If I change it to stLinkCriteria = "[Season]='" & Me![cboSeasonID] &
"'"
it works just fine.

Please help a dumb Texan.

What is the Datatype of the [Week] field?
Probably it's a number, not text, so try:
stLinkCriteria = "[Season]='" & Me![cboSeasonID] & "' AND [Week]= "
& Me![cboWeek]

Your debug statement should then read:
[Season]='2005/2006' AND [Week]=9
 
G

Guest

Rick,
I think fredg's answer will solve your problem, but you being a Texan, I
feel compelled to point something out to you. Never ask anyone where they
are from. If they are from Texas, they will tell you. If they are not,
there is no sense in embarresing them.
 
R

Rick

Fred,

It worked perfectly. Not only have you solved my problem, you taught
me something... and that is the most thing you could have done.
Thank you very much!!!

Rick aka A little less dumb Texan
 
B

Berny

Hello,

I'm having a similar problem but I'm trying to include a multi-list bos
selection to my criteria.

I'm at the end of my rope trying to make this work.

can anyone get me a push in the right dirrection?

I'm using the following code to make the multi-list selection

If Me!TradeSelection.ItemsSelected.Count > 0 Then
For Each varTradeItem In Me!TradeSelection.ItemsSelected
strTradeCriteria = strTradeCriteria & "Trade = " & Chr(34) &
Me!TradeSelection.ItemData(varTradeItem) & Chr(34) & "OR "

Next varTradeItem
strTradeCriteria = Left(strTradeCriteria, Len(strTradeCriteria) - 3)
Else
MsgBox "You have not made a selection" , vbExclamation, "Nothing to
find!"
End If

Then I'm trying to add another field on the form called SBKG to the
LinkCriteria

stLinkCriteria = "[SBKG]= '" & Me![cboSBKG] & "' And [Trade]= '" &
strTradeCriteria & "'"

the goal is to open the following report but I can't figure-out what I doing
wrong

DoCmd.OpenReport strDocName, acViewPreview, , stLinkCriteria

I would appreciate any help you can provide

Thank you
 

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