Avatar of SteveL13
SteveL13Flag for United States of America

asked on 

Error can't find table ??

I am trying to open a report filtered by the current user.  But I'm getting an error saying the d/b can't find the table or it is misspelled.  It is spelled correctly.  Do I have a syntax issue with this code...

DoCmd.OpenReport "rptReferrals", acViewPreview, , "[Agent] = '" & DLookup("[CurrentUser]", "LOCALtblCurrentUser" & "'"), acWindowNormal
Microsoft Access

Avatar of undefined
Last Comment
Gustav Brock
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

try something like

dim strAgent as string
strAgent=Dlookup("CurrentUser", "LOCALtblCurrentUser")

debug.print strAgent

DoCmd.OpenReport "rptReferrals", acViewPreview, , "[Agent] ="" & strAgent & "'"

or this

DoCmd.OpenReport "rptReferrals", acViewPreview, , "[Agent] = '" & DLookup("[CurrentUser]", "LOCALtblCurrentUser") & "'" acWindowNormal
Avatar of PatHartman
PatHartman
Flag of United States of America image

Check the syntax of the DLookup().  What is the --- & "'"  --- before the ending parenthesis?
Avatar of SteveL13
SteveL13
Flag of United States of America image

ASKER

Rey,

I am trying your first suggestion but am getting "Syntax error in string in query expression '[Agent] =" & strAgent & '

The degug.print returns the correct string of characters.
SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo