473,507 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ADO Recordset as a Form Recordset?

twinnyfo
3,653 Recognized Expert Moderator Specialist
Hello, Friends!

It's been a while since I've had the chance to be on here, but I've run across a snag, which I think should have a relatively easy solution, but I am at a loss.

Background:
I have a bunch of files saved in folders on our network. They are all saved in individual folders. I want users to be able to select which folder and see a list of files in that folder, then either open or print one of those files.

What I want:
I want a Continuous Form with a Command Button for each record allowing the user to view or print. There will also be a Text Box which lists the file name the user has access to.

What I've done so far:
The Form itself, is easy-breezy, Command Buttons are no problem for this type of thing. I've also been able to create an ADO Recordset that loops through the designated folder and creates the list of files in the Recordset. Looping through and Debug.Print gives me exactly the list of files that I want. No problems at all.

What I have been unsuccessful at:
Although I have been successfully able to assign the Recordset to the Recordset Property of the Form, AND I have ben able to successfully assign the Field Name to the Control Source of the Text Box in question, every time I open the Form, the Text Box only lists "#Error".

Listed below is the scaled down code.

Any ideas what I am doing wrong? I think this must be a simple oversight.

Please note: both the Form itself and the Text Box are Unbound until the Form opens.


Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Form_Open(Cancel As Integer)
  5. On Error GoTo EH
  6.     Dim strPath     As String
  7.     Dim rst         As ADODB.Recordset
  8.     Dim strFile     As String
  9.  
  10.     strPath = "C:\Folder\"
  11.  
  12.     Set rst = New ADODB.Recordset
  13.     With rst
  14.         Call .Fields.Append("Filename", adChar, 255)
  15.         Call .Open
  16.         strFile = Dir(strPath & "IDNum*.*")
  17.         Do While Not strFile = vbNullString
  18.             Call .AddNew
  19.             .Fields(0).Value = strFile
  20.             Call .Update
  21.             strFile = Dir
  22.         Loop
  23.         Set Me.Recordset = rst
  24.         Me.txtFilename.ControlSource = .Fields(0).Name
  25.     End With
  26.  
  27.     Set rst = Nothing
  28.  
  29.     Exit Sub
  30. EH:
  31.     MsgBox "There was an error listing the Files!  " & _
  32.         "Please contact your Database Administrator.", vbCritical, "WARNING!"
  33.     Exit Sub
  34. End Sub
Any hepp any o' all y'all can provide would be greatly appreciated. This one has Goofy scratching his head profusely!

:-)
Aug 22 '17 #1
7 3822
NeoPa
32,557 Recognized Expert Moderator MVP
Unusual to see a recordset with no SQL associated. A first for me.

I would say only two things :
  1. Is it necessary to use ADODB? Would DAO work better?
  2. If you'd like to send me a copy of the file to look at I'd happily do so for you. An intriguing situation I may learn from. PM for email details if you're interested.
Aug 22 '17 #2
twinnyfo
3,653 Recognized Expert Moderator Specialist
NeoPa,

I could only find info on creating a Recordset like this (some folks call them "disconnected" recordsets, and I've seen another name for them thrown around, but I can't remember what it was) using ADO.

I'd be glad to try to create one via DAO. These disconnected RSs are new to me, also. I have a whopping three hours experience on them!

And.... the whole thing is what was posted. Before I got too deep into building the entire automobile, I figured I'd make sure I could get the wheels spinning first....
Aug 22 '17 #3
twinnyfo
3,653 Recognized Expert Moderator Specialist
Notice Line 15 below added; AND Line 25 commented out, with the Text Box using "FileName" as its bound Control Source. For whatever reason, Line 15 must be included. It works like a charm. I hope others may benefit from my head-scratching (and hair-pulling-out).

This is a good way to use a Recordset as the RecordSource for a Form (apparently when you set the Recordset Property, you are also setting the RecordSource Property). And now I'm apparently one of the few people who've been able to do it successfully.

I am sure there are numerous uses for this type of thing, but one could use it for listing files for the User, listing objects in a DB. I'm not sure I have much use beyond my initial concerns, but there may be applications for this in the future.

Hope this hepps!

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Form_Open(Cancel As Integer)
  5. On Error GoTo EH
  6.     Dim strPath     As String
  7.     Dim rst         As ADODB.Recordset
  8.     Dim strFile     As String
  9.  
  10.     strPath = "C:\Folder\"
  11.  
  12.     Set rst = New ADODB.Recordset
  13.     With rst
  14.         Call .Fields.Append("Filename", adChar, 255)
  15.         .LockType = adLockOptimistic
  16.         Call .Open
  17.         strFile = Dir(strPath & "IDNum*.*")
  18.         Do While Not strFile = vbNullString
  19.             Call .AddNew
  20.             .Fields(0).Value = strFile
  21.             Call .Update
  22.             strFile = Dir
  23.         Loop
  24.         Set Me.Recordset = rst
  25. '        Me.txtFilename.ControlSource = .Fields(0).Name
  26.     End With
  27.  
  28.     Set rst = Nothing
  29.  
  30.     Exit Sub
  31. EH:
  32.     MsgBox "There was an error listing the Files!  " & _
  33.         "Please contact your Database Administrator.", vbCritical, "WARNING!"
  34.     Exit Sub
  35. End Sub
Aug 22 '17 #4
twinnyfo
3,653 Recognized Expert Moderator Specialist
According to ADezii, DAO does not support Disconnected Recordsets.
Aug 22 '17 #5
NeoPa
32,557 Recognized Expert Moderator MVP
If ADezii says that I expect it's true. He's quite a bright lad if truth be told.

Thank you TwinnyFo for this example, and particularly the solution. Very interesting work :-)

Unusually, I've selected your solution post as Best Answer. This seems appropriate in these circumstances.
Aug 23 '17 #6
twinnyfo
3,653 Recognized Expert Moderator Specialist
NeoPa,

I guess there are times when I do something right.... And I didn't want to presume and select my post as an answer. :-O

Miss you guys! Might be back on here soon for some other quirky questions.
Aug 23 '17 #7
NeoPa
32,557 Recognized Expert Moderator MVP
Twinnyfo:
And I didn't want to presume and select my post as an answer.
Generally best avoided. Moderators have that responsibility so they may do so if and when they believe their post is instructive and generally helpful for anyone searching for the same question. That was true in this case but rarely so for those who come back to answer their own questions.

Not that we want to discourage any member from doing that. Far from it. We love it when they do. Rarely though are they candidates for Best Answer.
Aug 23 '17 #8

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

Similar topics

6
22175
by: deko | last post by:
I have several stored queries that provide views based on user selection - selection criteria is stored in strPxSx, and the query called would then be "qrySearch24" or "qrySearch19", for example. ...
2
7910
by: ano1optimist | last post by:
I have a form with a search button. I'm using command parameters to pass search criteria to a stored procedure. Here is my code: Stored procedure: CREATE PROCEDURE . @strCriteria varchar(200)...
3
5266
by: Kim Baker | last post by:
Problem creating a recordset object from another recordset object. 1. create first object. rstTemp with 10 fields - no problem 2. create second object rstTemp2 with one field - no problem 3....
1
6187
by: Rémi | last post by:
Hello! I have a very general question for old Access hands. I am familiar with a form's Recordset and RecordsetClone properties. In what cases do you choose to use one over the other? Are there...
3
2770
by: shumaker | last post by:
This code from the subform works for getting the value of a field of the main form named "WorkSheet": MsgBox Form_WorkSheet.Recordset.Fields("Clerk").Value Each record in the mainform datasheet...
11
18805
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that...
7
5268
by: JC | last post by:
Hey Folks, I am having a problem and I need some expert help. I am trying to populate a list box with a record set based off of a table field on the open procedure. I then want to have that...
2
10436
by: Tom Clavel | last post by:
Scratching my head. I am using the filter property on a combo box .AfterUpdate event to get to a single client record. This is causing a some strange behavior: As I enter a subform, I get a no...
1
2463
by: questionit | last post by:
Hi This is duplicate post due to no answert.. its a bit urgent Me.Form.RecordSource = strSQL How can i get the record count by using above statement. I am interested in getting '0'...
11
4019
by: OldBirdman | last post by:
I have a form with several bound textboxes. These are routinely updated by User. The table in RecordSource for this form currently has 8 fields not shown on this form, but which occasionally need...
0
7111
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...
1
7031
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
7485
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
5623
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,...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
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
3191
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
1542
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 ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.