473,503 Members | 1,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using a Recordset in DLookup

62 New Member
Hello -

I have an Access 2007 database that has an ODBC connection to several very large, non-updateable tables in our CRM system.

I would like to speed up my app by using a recordset as the source for some DLookup fields in my forms.

I found and have adapted the following code that runs when I load my Dashboard, the first form that loads whent the app is opened.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. Dim conn As New ADODB.Connection
  4. Dim rst As New ADODB.Recordset
  5. Dim strg As String
  6. strg = "Provider=Microsoft.ACE.OLEDB.12.0;" _
  7.         & " Data Source=\\Network\Folder\subfolder\susubfolder\MyDatabase.accdb;" _
  8.         & " Password=MyPassword;Persist Security Info=False"
  9. conn.Open strg
  10. Dim strsql As String
  11. strsql = "SELECT dbo_INT_AUX_DIR_LIST.LISTING_ID, q_FolderList.DIRECTORY_NM" _
  12.         & " FROM (dbo_INT_AUX_LISTING LEFT JOIN dbo_INT_AUX_DIR_LIST " _
  13.         & " ON dbo_INT_AUX_LISTING.LISTING_ID = dbo_INT_AUX_DIR_LIST.LISTING_ID) " _
  14.         & " LEFT JOIN q_FolderList " _
  15.         & " ON dbo_INT_AUX_DIR_LIST.CONTAIN_DIR_ID = q_FolderList.DIRECTORY_ID" _
  16.         & " WHERE (((q_FolderList.DIRECTORY_NM) Not LIKE '*" & "firm lawyers" & "*' " _
  17.         & " And (q_FolderList.DIRECTORY_NM) Not LIKE '*" & "Companies (Public)" & "*') " _
  18.         & " AND ((dbo_INT_AUX_LISTING.LISTING_TYP_IND)=1))" _
  19.         & " ORDER BY dbo_INT_AUX_DIR_LIST.LISTING_ID "
  20.  
  21. rst.ActiveConnection = conn
  22.  
  23. 'to open a recordset, a source (strsql) and an ActiveConnection(conn) are provided.
  24.  
  25. rst.Open strsql, conn
  26.  
  27. MsgBox ("open")
  28.  
  29. Set rst = Nothing
  30. Set conn = Nothing
  31.  
  32. End Sub
Question 1 - errors
I am getting a
Compile error: User-defined type not defined
at line 3.

I had this code in a test database and it worked fine until line 9, where I got the error:

Run-time error '-2147217843 (80040e4d)':
Cannot start your application. The workgroup information file is missing or opened exclusively bby another user.


Both databases are in the same network directory.

Question 2 - Connecting
How do I reference this recordset in my DLookup where q_CompanyStatus has been replaced by the RecordSet? I am not sure where the RecordSet is named.
Expand|Select|Wrap|Line Numbers
  1. =DLookUp("DIRECTORY_NM","q_CompanyStatus","Comp_ID = " & [Company_ID])
Many thanks!
Sandra
Jan 30 '12 #1
5 10691
Rabbit
12,516 Recognized Expert Moderator MVP
You can't reference a VBA recordset object using DLookup.
Jan 30 '12 #2
Sandra Walsh
62 New Member
Well that solves that!!

Thanks :-)
Jan 30 '12 #3
ADezii
8,834 Recognized Expert Expert
You ca use the 'Find' Method of the Recordset Object if you so desire. The General Idea would be:
Expand|Select|Wrap|Line Numbers
  1. 'Must have a Reference to the Microsoft ActiveX Data Objects X.X Object Library
  2. Dim rst As ADODB.Recordset
  3. Dim strSearchString As String
  4. Dim strSQL As String
  5.  
  6. strSQL = "Select * FROM tblEmployees;"
  7. strSearchString = "Flintstone"
  8.  
  9. Set rst = New ADODB.Recordset
  10.  
  11. With rst
  12.   .Source = strSQL
  13.   .ActiveConnection = CurrentProject.Connection
  14.   .CursorType = adOpenKeyset
  15.   .LockType = adLockReadOnly
  16.     .Open
  17.  
  18.   .Find "[Last] = '" & strSearchString & "'"
  19.  
  20.     'Record found matching Criteria
  21.     If Not .EOF Then
  22.       MsgBox ![First] & " " & ![Last] & " | Record# " & .AbsolutePosition
  23.     Else
  24.       MsgBox strSearchString & " not found!"
  25.     End If
  26. End With
  27.  
  28. rst.Close
  29. Set rst = Nothing
Jan 30 '12 #4
Sandra Walsh
62 New Member
Thanks, AD - I will give that a try :-)
Jan 30 '12 #5
NeoPa
32,557 Recognized Expert Moderator MVP
This question should have been reported and deleted as it's an attempt to deal with multiple issues in the same thread.

It has a valid answer posted so I won't delete it now, but to avoid the temptation for anyone of continuing with other aspects of the Opening Post I will close it now. I am however, open to any questions or alternative suggestions on this via PM.

@Sandra.
Please check out how we expect threads to be posted here. There are two threads at the very top of the forum that deal with this and, in this particular case which includes posted code, you need to read When Posting (VBA or SQL) Code before doing so again.
Jan 30 '12 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7261
by: Markus | last post by:
Hello, I'm running on Mac OS X and need to create a soft link to a file. I tried both makealias() and link(). While makealias creates a Finder alias just fine my application that needs to read...
2
1297
by: Rootshell | last post by:
I need to create the table and I want to edit its content from www level. Here is some example: http://www.rootshell.be/~flash44 There is a table. Is there possibilty to edit the content...
9
2057
by: jon wayne | last post by:
OK! I had this nagging doubt Consider (without worrying abt access specifiers) class Kid : public Parent{...}; Parent::someFunc() { Kid k; }
2
6063
by: ajspacemanspiff | last post by:
I currently have a solution that requires 2 sub queries, where each of them is convereted into a crosstab query and then I join the crosstab queries to a result. I would like to make this more...
2
2860
by: aj902 | last post by:
Hello , I am trying to create a program where all detail, http://www.albany.edu/~csi333/projects.htm
1
1182
by: Daylor | last post by:
few questions about Delegate in vb.net : do i need to create NEW delegate each time i use invoke ? or i can use the same delegate object when using specific invoke ? and if can use the same...
2
1287
by: Gasnic | last post by:
Hi I need to create a .NET object that will be serialized into the following xml structure ( I can't change the XML schema) <Root> <Record> <Field1>data1</Field1> <Field2>data2</Field2>...
4
1194
by: jimgardener | last post by:
hi am a beginner in python and PIL .I need to read an RGB 8 bit image (am using jpeg )and pack the rgb color values into a double value so i can store the image as a list of pixelvalues.From my...
6
1766
by: boikobo tlhobogang | last post by:
i am designing an application for a company where i am an intern.i need to create an access database that keeps information about insurers,brokers,individual agent,corporate agent and sub agent.i am...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.