filter a form on load

markdooler

Member
Local time
Today, 14:46
Joined
Nov 25, 2020
Messages
58
Hi All

Need some help again!

i have a form that displays all the users in my system called frmUserList (form created from the tblUsers)

I also have an edit user form called frmEditUsers

I have set the on click event on the fields in the frmUserList to open the frmEditUsers but cant seem to get it to filter to the correct record.

Below is the macro setup i have used in the past for another form with this funtion but i just cant get it to work

1612189219901.png


with it set like this the below comes up when you click it.

1612189260656.png


Im sure i have not given you enough info but any ideas?
 

Attachments

  • 1612189029491.png
    1612189029491.png
    72 KB · Views: 163
numbers to not need quotes around the text box,
Strings (username) require (single) quotes: where [LastName]= '" & txtName & "'"

Note: using single quotes will fail if the name has a single quote in it like: O'brien, etc.
So you can use Dbl-quotes " ,but that will fail if that has a dbl-quote in it. (tho more rare for names)
You cant quote a quote.

I have a
public Constant Q = """"
then its: where [LastName]= " & Q & txtName & Q
 
numbers to not need quotes around the text box,
Strings (username) require (single) quotes: where [LastName]= '" & txtName & "'"

Note: using single quotes will fail if the name has a single quote in it like: O'brien, etc.
So you can use Dbl-quotes " ,but that will fail if that has a dbl-quote in it. (tho more rare for names)
You cant quote a quote.

I have a
public Constant Q = """"
then its: where [LastName]= " & Q & txtName & Q
ok so have tried this

1612194678705.png


But still no joy.

So to be clear, i want the form (frmEditUser) to only display the record that is clicked on the form (frmUserList).

The txtUserName is the same on both forms.

I have done this sucessfully with numbers bit cant seem to do it using text!
 
Use VBA instead:

Code:
DoCmd.OpenForm "frmEditUsers", , ,"[LastName] = '" & Forms![frmUserList]![txtUserName & "'"   'note that [LastName] is the name of the field in the form's record source

Cheers,
Vlad
 
Use the VBA solution posted by Vlad but enclose the name with double quotes since single quotes are too common to ignore.
 
Use VBA instead:

Code:
DoCmd.OpenForm "frmEditUsers", , ,"[LastName] = '" & Forms![frmUserList]![txtUserName & "'"   'note that [LastName] is the name of the field in the form's record source

Cheers,
Vlad
The code

1612217344694.png


The error

1612217379427.png


Any ideas?
 
I guess you didn't read my post #5. Also, LastName is unlikely to be unique so who knows what record you would end up on. The error may be occuring because you are using a lookup field on your table and the data value isn't what you think it is.
 
I guess you didn't read my post #5. Also, LastName is unlikely to be unique so who knows what record you would end up on. The error may be occuring because you are using a lookup field on your table and the data value isn't what you think it is.
Sorry, i did i just wanted to get it working before i played with the syntax.

I have already changed LastName to UserName as this is unique to each user.

Still cant work out why it doesn't work tho.
 
Do you have lookups defined on the table? They will interfere with what you are trying to do.

PS. Do it right the first time. You don't want to have to go back once something is "working" looking for code you know for a fact will cause errors.
 
Do you have lookups defined on the table? They will interfere with what you are trying to do.

PS. Do it right the first time. You don't want to have to go back once something is "working" looking for code you know for a fact will cause errors.
Very true

The frmUserList is a form based on qryCusrrentSiteUsers that filters the tblUsers using a tempvar for the site that the user is logged in as.

I have a similar set of queries that are first filtered by the site, then by the user name, then a click to update function based on a number and this works fine.

As i see it im trying to do the same but around text rather than numbers.

Hopefully that makes sense.
 

Users who are viewing this thread

Back
Top Bottom