quick question - strWhere with WHERE (1 Viewer)

Misiek

Registered User.
Local time
Today, 15:26
Joined
Sep 10, 2014
Messages
248
Hello all,

I'm struggling to find answer online, perhaps not asking right question.
In one of my forms I use Alan Browne's filtering code

http://allenbrowne.com/ser-62code.html

This shows all records with specific user:
Code:
    If Not IsNull(Me.cboUser) Then
        strWhere = strWhere & "([tUserFK] = """ & Me.cboUser & """) AND "
    End If

I want to show all records for a group of users.
In table T_user i have UserID, UserName, UserResource, where rescue is a yes/no field.

in standard SQL query this would work:
Code:
...
WHERE (UserResource=True)
...

I can't work out how to translate it into vba.
Can anyone advice please.
Thank you
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:26
Joined
Aug 30, 2003
Messages
36,139
Is this what you're after?

strWhere = strWhere & "([tUserFK] = """ & Me.cboUser & """) AND UserResource=True AND "
 

Misiek

Registered User.
Local time
Today, 15:26
Joined
Sep 10, 2014
Messages
248
Thank you.

I think so, will try it tomorrow at work.
can i skip this part?

""" & Me.cboUser & """

As I don't want to select any user, just click on button and the code will run in background giving me wanter result.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:26
Joined
Aug 30, 2003
Messages
36,139
Oh sure, try

strWhere = strWhere & "UserResource=True AND "
 

Misiek

Registered User.
Local time
Today, 15:26
Joined
Sep 10, 2014
Messages
248
I tried this yesterday but when I run it it shows prompt to enter userResource instead of filtering. Like it doesn't know this filled name. The spelling is 100% correct.
I also tried TableName.fieldname = true.
But this gives the same prompt :/
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:26
Joined
Aug 30, 2003
Messages
36,139
Can attach the db here?
 

Misiek

Registered User.
Local time
Today, 15:26
Joined
Sep 10, 2014
Messages
248
please see stripped version.
 

Attachments

  • test.accdb
    1.4 MB · Views: 66

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:26
Joined
Aug 30, 2003
Messages
36,139
The field name is correct, but the field is not selected in the query underlying the form. ;)
 

Misiek

Registered User.
Local time
Today, 15:26
Joined
Sep 10, 2014
Messages
248
So I just need to simply add it to q_actionplanner?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:26
Joined
Aug 30, 2003
Messages
36,139
Yes; did you try it?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:26
Joined
Aug 30, 2003
Messages
36,139
Oh, I changed this back too:

strWhere = strWhere & "(uCommonResurce=true) AND "
 

Misiek

Registered User.
Local time
Today, 15:26
Joined
Sep 10, 2014
Messages
248
Yes works superb!
Would never think this was the problem.
Many thanks :)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:26
Joined
Aug 30, 2003
Messages
36,139
Happy to help!
 

Misiek

Registered User.
Local time
Today, 15:26
Joined
Sep 10, 2014
Messages
248
Hello again,
Unfortunately I found another problem,

When I open the form and click Filter button, it gives 12 records, then click REPORT button and I still have 12 records. All of it is ok.

Please memorize 1st and 2nd record

issue 1.
When I click Common Resource button I only get 1 record, but should see 2. (the first 2 from previous filtering.

issue2.
the filter Common resource doesnt "save" and then pass strWhere to report.

Any advice on that, please?

Thank you


________________________________
update:

issue 1 resolved, added extra brackets

had:
(...) OR (...)

changed to:
((...) OR (...))


issue 2
Fixed. Command the opens report was applying original filter before running report. My error when coding.
 
Last edited:

Users who are viewing this thread

Top Bottom