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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

applying an automatic filter to a form

Status
Not open for further replies.

tazibc

Instructor
Oct 5, 2007
66
GB
Pls pls help anyone this is killing me:-

I have created a login form using the code below:-

Private Sub Command5_Click()
Username.SetFocus
If Username = "user1" And Password = "user1" Then
MsgBox "Access Granted"
DoCmd.Close
DoCmd.OpenForm "Crystal Compliance Database"
Else
MsgBox "Please Enter Correct Username or Password"
End If
End Sub

so the login form will only ever open the form "Crystal Compliance Database". The problem is that I have a feild in the form called "service centre / satellite" this lists the location of a depo i.e a depo could be in Basingstoke. Is there anyway that when the user logs in this will open the form "crystal compliance database" and shows data on the form for depo basingstoke.

help much appreciated
 
Yep, the fourth parameter of the OpenForm method (WhereCondition) allows you to pass a valid WHERE statement to the form you're opening.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
Thanks Harley:-

but could you tell me what the code would look like I am new to access. I mean where would it fit into this code:-

Private Sub Command5_Click()
Username.SetFocus
If Username = "user1" And Password = "user1" Then
MsgBox "Access Granted"
DoCmd.Close
DoCmd.OpenForm "Crystal Compliance Database"
Else
MsgBox "Please Enter Correct Username or Password"
End If
End Sub


using my feild "Service centre/ Satellite" to = basingstoke on the form.

pls pls help
 
Is the Crystal Compliance Database form bound to a table or is it just your one Service centre/ Satellite field that's bound to a table?

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
The whole form is bound to a table
 
That helps, something like:
Code:
DoCmd.OpenForm "Crystal Compliance Database",,,"WHERE [YourField] = 'Your Criteria for a Basingstoke Record'"
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
Harley, FYI, don't put the WHERE keyword in the 4th parameter ...
 
Yep, of course. [banghead]

Cheers PHV. It's been a long day mate. [blush]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
so guys would my code look like this:-

Private Sub Command5_Click()
Username.SetFocus
If Username = "user1" And Password = "user1" Then
MsgBox "Access Granted"
DoCmd.Close
DoCmd.OpenForm "Crystal Compliance Database",,,"WHERE [YourField] = ' Basingstoke'"
Else
MsgBox "Please Enter Correct Username or Password"
End If
End Sub
 
Take the WHERE keyword out (as PHV mentioned, sorry that was my mistake) and replace [YourField] with the name of the field in your table you want to query and it should be good to go.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
does my feild have to be in the square brackets ?? for example:-

",,," [Service Centre / Satellite] = ' Basingstoke'
 
Hi Harley you've been a complete star and thanks for your help but when I add the filter to the query:-

Private Sub Command5_Click()
Username.SetFocus
If Username = "user1" And Password = "user1" Then
MsgBox "Access Granted"
DoCmd.Close
DoCmd.OpenForm "Crystal Compliance Database", , , "[Service Centre / Satellite] = ' Basingstoke'"
Else
MsgBox "Please Enter Correct Username or Password"
End If
End Sub

its brings back no records in my form for basingstoke but i know there are 30 odd records for basingstoke am I doing something wrong.......
 
Thanks Harley & PHV your both Stars in my book I got it to work thanks so much........
 
Glad to help [smile]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top