+ Reply to Thread
Results 1 to 4 of 4

Open an Access database Import data like Microsoft Query

  1. #1
    Registered User
    Join Date
    05-23-2007
    Posts
    23

    Cool Open an Access database Import data like Microsoft Query

    Up until now, I have been using Microsoft Query to retreive data from MS Access database. This has worked well, so far. I also like using SQL statements (criteria) and MS Query Data Range Properties. But this project has gone beyond this.
    I need to create a user form to open and transfer data from several Access tables using VBA code from an Excel application that will do the following:

    Create UserForm with 3 drop down boxes and 2 command buttons.
    Command buttons will be named 'New Week' and 'Review Week'
    Each drop down box will contain a parameter (a user choice)
    Drop down box 1 will import it's data from the Access DB as 1 field in XYZ table
    Choices made in drop down box 2 & 3 will be validated in each command button's code.
    The basic code for each command button will be the same except, one button will open all Access tables as read only and the other will open one table as read/write or read/append.

    I have searched the web and have a new book to try to help with this, but there seem to be 100 different ways to do this. I basically have 3 questions for this:

    1. How to open or connect to a database (like MS Query does) and I perfer to use SQL?
    2. How to set the Data Range Properties with code?
    3. How to set up a drop down list box on a user form and use an Access DB field as the list's data?

    Any help will be greatly appreciated...

    Thanks
    Ed
    Last edited by hilander; 05-27-2007 at 03:07 AM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Ed

    Here's one way for points 1 and 3

    Please Login or Register  to view this content.
    It uses the form initialization code to get the distinct entries from table access_table1, field col_1 from database c:\temp\test2.mdb and loads them into a combobox. Same syntax for a listbox.

    I'm not sure what you mean by point 2. Data range properties from what? / where???


    HTH

    rylo

  3. #3
    Registered User
    Join Date
    05-23-2007
    Posts
    23

    Opening ADO database multiple queries

    Thanks for the response. To answer your question, Data Range Properties is part of MS Query. When you select a range on a worksheet and import data in that range, the Data Range Properties' form gives you different options on how the returned data is used.

    I have looked at your code and other code from the web. All of which is very similar. Is there a way to have multiple tables or multiple fields for multiple combo boxes on the same user form, without having to go thru all of that code?

    In other words, do I need to open more connections and assign recordset variables for each control on a user form? I realize more SQL statements will be needed. Isn't there an ADO recordset control that can be placed on a user form that handles most of the work?

    Also, is there a way to open a table as read only or read/write?

    Thanks
    ED

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Ed

    You only need to open the one connection. From that you could either open multiple recordsets, reuse the same recordset for each item, or, depending on your database table / query structure, you could have 1 recordset that has all the data for all your output areas, and use the single loop to fill each output from the same recordset.

    There are probably various ways to code your requirement, but without some specifics, the above generalisation is the best I can come up with.

    You can open tables with different access methods. Again, depends on what you want to do will determine your approach. Are you trying to add new records? or update existing records???


    rylo

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1