473,569 Members | 2,705 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 10712
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,564 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
7271
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 the reference file doesn't like this. link() produces 1) a hard link and b) gives me the following error: OSError: Operation not supported I...
2
1304
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 using <input> command?
9
2064
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
6069
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 dynamic and allow for users to filter, and to do so I would like to be able to create the resulting query all in VBA code. I can create a...
2
2864
by: aj902 | last post by:
Hello , I am trying to create a program where all detail, http://www.albany.edu/~csi333/projects.htm
1
1185
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 one, in case its multithread application, i need to put it in synclock ? --------------
2
1289
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> <Record> <Record>
4
1196
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 application i should be able to call rgbimage1.getpixellist() to retrieve the double values of an image. Do i need to create a new class for this?I...
6
1768
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 stuck because i fail to create the database as i have less skills in the design using access.i dont know how to code using vba i did only java and php...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
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 we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.