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
- Option Compare Database
- Option Explicit
- Private Sub Form_Open(Cancel As Integer)
- On Error GoTo EH
- Dim strPath As String
- Dim rst As ADODB.Recordset
- Dim strFile As String
- strPath = "C:\Folder\"
- Set rst = New ADODB.Recordset
- With rst
- Call .Fields.Append("Filename", adChar, 255)
- Call .Open
- strFile = Dir(strPath & "IDNum*.*")
- Do While Not strFile = vbNullString
- Call .AddNew
- .Fields(0).Value = strFile
- Call .Update
- strFile = Dir
- Loop
- Set Me.Recordset = rst
- Me.txtFilename.ControlSource = .Fields(0).Name
- End With
- Set rst = Nothing
- Exit Sub
- EH:
- MsgBox "There was an error listing the Files! " & _
- "Please contact your Database Administrator.", vbCritical, "WARNING!"
- Exit Sub
- End Sub
:-)