Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 28th, 2004, 06:50 PM
Authorized User
 
Join Date: Dec 2003
Location: Nashville, Tennessee, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Automate adding record and populating field

I would like to add new records to a table (one for each file name) and populate a field with each of the file names in a directory. And I want to do it with the push of a button. I have not figured out how to automate this process and would really appreciate any help you can give me.

Nashville_Bill
__________________
Nashville_Bill
Reply With Quote
  #2 (permalink)  
Old January 28th, 2004, 09:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Melbourne, Vic, Australia.
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Put this code in your button's Click event procedure:
(You might want to declare the variables, which is something I haven't done in this example)
Code:
DoCmd.SetWarnings False
Set fso = CreateObject("Scripting.FileSystemObject")
Set folderObject = fso.GetFolder("C:\Some\Directory")
Set filesObject = folderObject.Files

For Each file In filesObject
DoCmd.RunSQL "INSERT INTO YourTable (YourField) VALUES ('" & file.Name & "');"
Next
DoCmd.SetWarnings True
Of course - you'll need to change the bits
C:\Some\Directory
YourTable
YourField

Steven

I am a loud man with a very large hat. This means I am in charge
Reply With Quote
  #3 (permalink)  
Old January 29th, 2004, 11:57 AM
Authorized User
 
Join Date: Dec 2003
Location: Nashville, Tennessee, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Steven,

Thanks for the response. I get an compile error message that says the variable file is not defined:

    Dim fso As Object
    Dim folderObject As Object
    Dim filesObject As Object
    DoCmd.SetWarnings False
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folderObject = fso.GetFolder("C:\PICS\Pic\1")
    Set filesObject = folderObject.Files

    For Each file In filesObject

Did I forget to do something?

Nashville_Bill
Reply With Quote
  #4 (permalink)  
Old January 29th, 2004, 12:25 PM
Authorized User
 
Join Date: Dec 2003
Location: Nashville, Tennessee, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I added a DIM for file and all is well now.

Thanks a lot!



Nashville_Bill
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
populating a listbox with a field contains comma bjcountry Access 3 February 17th, 2016 05:07 PM
Automate Exporting data to text file if new record NC_Juggler Access VBA 1 November 21st, 2008 04:35 PM
populating drop down through text field nasirmunir Javascript How-To 5 June 30th, 2008 11:01 AM
Populating field Popper Javascript How-To 10 September 23rd, 2004 06:06 PM
populating a text field sand133 VB.NET 2002/2003 Basics 12 June 18th, 2004 08:49 AM



All times are GMT -4. The time now is 10:00 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.