setting query criteria from a form (I don't know what to call thi

G

Guest

I have a query named [qryStudyAllInterested]. There are no criteria for this
query, it is used to combine two tables into one query. I have created a form
named [frmStudyAllInterestedSelect] that has one button named
[btnStudyAllInterested] and one lookup field named [cbxStudyID] that does not
have a control source.

I would like to select a study from a drop down list using the [cbxStudyID]
field. Then press the [btnStudyAllInterested] button. Upon pressing this
button I would like Access to open a different form named
[frmStudyAllInterested] that is in tabular view and linked (record source) to
the [qryStudyAllInterested] query.

I have written VBA code (see what follows). But when I select a study from
the [cbxStudyID] drop box and then click on the [btnStudyAllInterested]
button I receive the following error.

"Syntax error (missing operator) in query expression '[StudyID]= "the value
selected in the [cbxSudyID] drop box displays here"'"

PLEASE HELP.

VBA programmed to the button [btnStudyAllInterested]:

Private Sub btnStudyAllInterested_Click()
On Error GoTo Err_FilterIssues_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmStudyAllInterested"
stLinkCriteria = "[StudyID]=" & cbxStudyID

If DCount("StudyID", "qryStudyAllInterested", stLinkCriteria) Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
' Close the dialog box.
DoCmd.Close acForm, "frmStudyAllInterestedSelect"
End If

Exit_btnStudyAllInterested_Click:
Exit Sub

Err_FilterIssues_Click:
MsgBox Err.Description
Resume Exit_btnStudyAllInterested_Click

End Sub
 
G

Guest

Boy was I far off. heh. I was making this much more difficult than I needed
to. This is the VBA:

Private Sub btnStudyAllInterestedSelect1_Click()
On Error GoTo Err_btnStudyAllInterestedSelect1_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmStudyAllInterested"

stLinkCriteria = "[StudyID]=" & "'" & Me![cbxStudyID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_btnStudyAllInterestedSelect1_Click:
Exit Sub

Err_btnStudyAllInterestedSelect1_Click:
MsgBox Err.Description
Resume Exit_btnStudyAllInterestedSelect1_Click

End Sub
 

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