applyfilter problem

knowledge76

Registered User.
Local time
Today, 23:46
Joined
Jan 20, 2005
Messages
165
Hello friends,
I have a problem with my vba code by applying the applyfilter property, my code which is listed below first open the query qithout using filter and then reopen the query to applyfilter. Is there anyway I can do it in one step?
Code:
Private Sub Befehl38_Click()

On Error GoTo Befehl38_Click_fehler
Dim strdoc As String
strdoc = "SUM_BYCOUNTRY"

DoCmd.OpenQuery strdoc, acViewNormal
DoCmd.ApplyFilter , "[Country Repaired] ='GBR'"

Befehl38_Click_fehler:
Exit Sub

End Sub
 
Are you filtering in a form? If so I would apply the filter to the form not to the underlying query.

me.Filter = "[Country Repaired] ='GBR'"
me.FilterOn = True

This is a one-step solution

hth
Chris
 
Are you filtering in a form? If so I would apply the filter to the form not to the underlying query.

me.Filter = "[Country Repaired] ='GBR'"
me.FilterOn = True

This is a one-step solution

hth
Chris

I am filtering using a form, not in a form. I am calling a query as stated in my code. For a query that does not take much time to run you dont even recognise that first query is opened and then the filter is set, but for a query which shows a lot of data, it takes too much time and it looks very unprofes.
 
From what I gather you are attemptiing to open a form based on a large underlying tabel or query and it is taking a long to open as Access has to validate the table or query.

If my assumptions are correct then try this.

1 do not assign a recordsource to the form

2 instigate a timer event on the form, say 1000 - 1 second.

3 on the timer event set the timerinterval to 0 then set the recordsource to the form using the Me.RecordSource = "...."

This method opens the form for the users benefit and then after 1 second applies the recordsource.

CodeMaster::cool:
 
Sorry that I am not understanding that well or I am not able to describe my problem that well. I just want to click a button which should run a query and show me in my case records from GBR. I have done that before without knowing that my code first opens the whole query and then apply the filter. I have done this with macro as well, will have to go to past and look how i implemented it.
 
Sorry that I am not understanding that well or I am not able to describe my problem that well. I just want to click a button which should run a query and show me in my case records from GBR. I have done that before without knowing that my code first opens the whole query and then apply the filter. I have done this with macro as well, will have to go to past and look how i implemented it.
Personally I don't this it is a good philosophy to use queries as a display/edit tool. I would always use a form because then you have much more control on how the interface performs. You can still use datasheet view in the form which will still allow you to present the data to look like query view. Moreover, you can handled the filters much better and it will look more professional than running a query.
hth
Chris
 

Users who are viewing this thread

Back
Top Bottom