By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,248 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,248 IT Pros & Developers. It's quick & easy.

How to output only the records of logged in user

P: 8
Hi experts,

I have a users table that lists the username, USERID and security level. That table is linked to another table that contains other data for the different users.

What I wish to accomplish is to be only to show the records of the user logged in based on the USERID. I was using this, but I get an error message:

Private Sub Form_Load()

If DLookup("tbl_Names", "[useridname] = '" & Forms![Frm_Names]!USERID & " '") Then
DoCmd.Open
Else
DoCmd.Close

End Sub

Where USERID is dervied froma a module that extracts user id from the computer and matches it with the field [useridname] in the tbl_Names.

Please help.

Thanks,
Enrique
Jan 9 '08 #1
Share this Question
Share on Google+
5 Replies


puppydogbuddy
Expert 100+
P: 1,923
Hi experts,

I have a users table that lists the username, USERID and security level. That table is linked to another table that contains other data for the different users.

What I wish to accomplish is to be only to show the records of the user logged in based on the USERID. I was using this, but I get an error message:

Private Sub Form_Load()

If DLookup("tbl_Names", "[useridname] = '" & Forms![Frm_Names]!USERID & " '") Then
DoCmd.Open
Else
DoCmd.Close

End Sub

Where USERID is dervied froma a module that extracts user id from the computer and matches it with the field [useridname] in the tbl_Names.

Please help.

Thanks,
Enrique
Try changing this:
If DLookup("tbl_Names", "[useridname] = '" & Forms![Frm_Names]!USERID & " '") Then

To this:
If Count(DLookup("[useridname]", "tbl_Names" , "[useridname] = '" & Forms![Frm_Names]!USERID & "'")) <> 0 Then
Jan 10 '08 #2

P: 8
Try changing this:
If DLookup("tbl_Names", "[useridname] = '" & Forms![Frm_Names]!USERID & " '") Then

To this:
If Count(DLookup("[useridname]", "tbl_Names" , "[useridname] = '" & Forms![Frm_Names]!USERID & "'")) <> 0 Then
Thanks PBD. However, I get a Complie Error Message: Wrong Number of Arguments or Invalid Property Assignment when I use If Count(DLookup("[useridname]", "tbl_Names" , "[useridname] = '" & Forms![Frm_Names]!USERID & "'")) <> 0 Then
Jan 10 '08 #3

puppydogbuddy
Expert 100+
P: 1,923
Thanks PBD. However, I get a Complie Error Message: Wrong Number of Arguments or Invalid Property Assignment when I use If Count(DLookup("[useridname]", "tbl_Names" , "[useridname] = '" & Forms![Frm_Names]!USERID & "'")) <> 0 Then

Sorry about that. I put the parens in the wrong place. Try this:

If Count(DLookup("[useridname]", "tbl_Names" , "[useridname] = '" & Forms![Frm_Names]!USERID & "'") <> 0) Then
Jan 10 '08 #4

P: 8
Sorry about that. I put the parens in the wrong place. Try this:

If Count(DLookup("[useridname]", "tbl_Names" , "[useridname] = '" & Forms![Frm_Names]!USERID & "'") <> 0) Then
Hi PDB,

Same error message. COUNT is highlighted then same Compile error
Jan 10 '08 #5

puppydogbuddy
Expert 100+
P: 1,923
Hi PDB,

Same error message. COUNT is highlighted then same Compile error
Sorry, I am having one of those days. You don't need the Dlookup, just a DCount. Try this:

If DCount("[useridname]", "tbl_Names" , "[useridname] = '" & Forms![Frm_Names]!USERID & "'") <> 0 Then
Jan 10 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.