Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using DoCmd.ApplyFilter 1

Status
Not open for further replies.

GIJoeFigure

Technical User
Jun 16, 2004
27
US
I'm having a problem using DoCmd.ApplyFilter to retrieve from a dataset. My code is below.

Private Sub Execute_Click()
Dim WhereClause As String
WhereClause = ""

'Each toggle turns off and on a different column to search
If Me!ProToggle = True Then
WhereClause = WhereClause & "[ViewPosition] = '" & Me![ViewPosition] & "' AND "
End If
If Me!ttToggle = True Then
WhereClause = WhereClause & "[DataType] = '" & Me![DataType] & "' AND "
End If
If Me!ICToggle = True Then
WhereClause = WhereClause & "[ImageComments] = '" & Me![ImageComments] & "' AND "
End If
If Me!BPToggle = True Then
WhereClause = WhereClause & "[BodyPartExamined] = '" & Me![BodyPartExamined] & "' AND "
End If
If Me!PPToggle = True Then
WhereClause = WhereClause & "[PatientPosition] = '" & Me![PatientPosition] & "' AND "
End If
If Me!IToggle = True Then
WhereClause = WhereClause & "[InstitutionName] = '" & Me![InstitutionName] & "' AND "
End If
If Me!FPToggle = True Then
WhereClause = WhereClause & "[DataPath] Like '*\" & Me![DataPath] & "*' AND "
End If

'Chop off the last AND
If Len(WhereClause) > 0 Then
WhereClause = Left(WhereClause, Len(WhereClause) - 4)
End If
resp = MsgBox(WhereClause & "Is this correct?", vbYesNoCancel)

' Now use the completed where statement to filter table entries
If resp = 2 Then Exit Sub
If resp = 7 Then
WhereClause = InputBox("What is the statement changes you would like?", , WhereClause)
End If

DoCmd.ApplyFilter WhereClause
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As you can see, its made to set up variable length whereclauses for the filter to use butI keep getting a runtime error saying that the last line doesn't work because my form is not bound to a table or query. Does anybody know how to solve what its asking for? Thanks in advance

J. Handfield
Interning Scientist
Eastman Kodak Research Labs
Rochester, NY 14650
 
What is the RecordSource property of your form ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for that PH, I just entered that as:

Forms!RunDicomQuery.RecordSource = "Sample Table"

The results are then kept on the form though. Is it possible to make the results show up in a table with all their columns of info like a simple query done with a wizard?

J. Handfield
Interning Scientist
Eastman Kodak Research Labs
Rochester, NY 14650
 
Take a look at the AllowDatasheetView property of your form.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'm not sure if you're still there PHV, but if you see this, I have a last question for you or anyone else with form-guided query knowledge. I saw the datasheet view and it only displayed the few columns that I sorted by and the others were ignored. If I didn't use all my sorting colums, for example 3 out of seven were used, how would I go about displaying all columns (since there are 30 with important information)?

J. Handfield
Interning Scientist
Eastman Kodak Research Labs
Rochester, NY 14650
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top