Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / November 2006

Tip: Looking for answers? Try searching our database.

Howto? Dlookup("field","SAVED_QUERY","Criteria='string'")

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jndrline - 03 Nov 2006 20:00 GMT
Dlookup("field","SAVED_QUERY","Criteria='string'")

I think it's not liking either using a saved query as a table, or it's not
liking that my string/date/number is a calculated expression in the query.

Thanks for your help.
undrline - 03 Nov 2006 20:23 GMT
According to the first couple of google results, it appears that the saved
query part shouldn't have a problem.
Opening the query, and typing in the string as the criteria manually, the
query runs fine.
So, I'm at a loss.  Here's my script:

Private Sub Auditor_Change()
Dim username As String
Dim phone As String
Dim site As String

' formula_user is the following query:
' SELECT tbl_user.User_ID, [User_First]+" "+IIf([User_MI] Is Null Or [User_MI]
="" Or [User_MI]=" "," ",[User_MI]+" ")+[User_Last] AS User_Name, tbl_user.
User_Site, tbl_user.User_Phone, tbl_user.Active_Employee
' FROM tbl_user;

username = Me.Auditor.Value
phone = DLookup("User_Phone", "formula_user", "Criteria = '" & username & "'")

site = DLookup("User_Site", "formula_user", "Criteria = '" & username & "'")

MsgBox "Name: " & username & vbNewLine _
& "Phone: " & phone & vbNewLine _
& "Site: " & site

End Sub

>Dlookup("field","SAVED_QUERY","Criteria='string'")
>
>I think it's not liking either using a saved query as a table, or it's not
>liking that my string/date/number is a calculated expression in the query.
>
>Thanks for your help.
Jndrline - 03 Nov 2006 20:27 GMT
Oh, and the error message:

"run-time error 2001
You canceled the previous operation"

>According to the first couple of google results, it appears that the saved
>query part shouldn't have a problem.
[quoted text clipped - 30 lines]
>>
>>Thanks for your help.
John Spencer - 03 Nov 2006 20:51 GMT
The last section of the DLookup is basically a where clause without the word
WHERE.  Any field you are querying against must be available in the query or
table.

DLookup("User_Phone", "formula_user", "User_Name = '" & username & "'")

That means that when the last section is evaluated it should become
  User_Name = 'Holly GoLightly'
assuming that Me.Auditor.Value is "Holly GoLightly"

> According to the first couple of google results, it appears that the saved
> query part shouldn't have a problem.
[quoted text clipped - 34 lines]
>>
>>Thanks for your help.
undrline - 03 Nov 2006 21:23 GMT
I figured it out probably right as you hit submit.  I was going to cross-post
on UtterAccess, and realized my mistake.  Silly me.  "Criteria="  Ha!

Thanks.

>The last section of the DLookup is basically a where clause without the word
>WHERE.  Any field you are querying against must be available in the query or
[quoted text clipped - 11 lines]
>>>
>>>Thanks for your help.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.