+ Reply to Thread
Results 1 to 15 of 15

Pull data from Access

  1. #1
    Registered User
    Join Date
    02-28-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    18

    Pull data from Access

    Hi All,

    I have data about 1200 rows 40 Columns in Access. I need to pull this data in excel using VBA. So the user will just select dropdowns in excel (around 4-5 dropdown) .This would be the criteria based on which data should be pulled..

    If its only criteria. I know how to pull data. But help needed when the user will have more than one criteria.


    Thanks in advance.


    Sujit

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Pull data from Access

    Hi sujitshukla
    what code do you have sofar?
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    02-28-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Pull data from Access

    Quote Originally Posted by pike View Post
    Hi sujitshukla
    what code do you have sofar?
    Hi,

    this is the code i am using

    Private Sub CommandButton1_Click()
    Dim con As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim r As Long
    con.Open "Provider=Microsoft.Jet.Oledb.4.0; " & _
    "data Source=C:\Documents and Settings\Administrator\Desktop\db1.mdb;"
    rs.Open "tbl_name", con, adOpenKeyset, adLockOptimistic, adCmdTable
    r = 6
    Do While Len(Sheet1.Range("A" & r).Formula) > 0
    With rs
    .AddNew
    .Fields("NAME") = Sheet1.Range("B" & r).Value
    .Update
    End With
    r = r + 1
    Loop
    rs.Close
    Set rs = Nothing
    con.Close
    Set con = Nothing



    End Sub

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Pull data from Access

    Hi sujitshukla
    Can you please add code tags to your script as per the rules and it makes the code easier to read

  5. #5
    Registered User
    Join Date
    02-28-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Pull data from Access

    Quote Originally Posted by pike View Post
    Hi sujitshukla
    Can you please add code tags to your script as per the rules and it makes the code easier to read
    Hi Pike..

    Sorry about that, but do you have a solution for my query. I am still struggling.

  6. #6
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Pull data from Access

    Hey sujitshukla
    If you can go back and edit and add code tags I can have a look

  7. #7
    Registered User
    Join Date
    02-28-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Pull data from Access

    Ok...Here it is sir

    Please Login or Register  to view this content.
    Now may i get something.

  8. #8
    Registered User
    Join Date
    02-10-2010
    Location
    Sacramento, Ca, USA
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    33

    Re: Pull data from Access

    Hi
    this is a code I use
    Please Login or Register  to view this content.
    You probably have to change it to fit your needs, but I hope it will help you.
    Gunilla

  9. #9
    Registered User
    Join Date
    02-10-2010
    Location
    Sacramento, Ca, USA
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    33

    Re: Pull data from Access

    Sorry this happens when you don't read the question to the end.
    Gunilla

  10. #10
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Pull data from Access

    Quote Originally Posted by sujitshukla View Post
    I have data about 1200 rows 40 Columns in Access. I need to pull this data in excel using VBA. So the user will just select dropdowns in excel (around 4-5 dropdown) .This would be the criteria based on which data should be pulled..

    If its only criteria. I know how to pull data. But help needed when the user will have more than one criteria.
    I am not sure that I fully understand your question but in your line of code (below)
    Please Login or Register  to view this content.
    this opens and retrieves the whole table.

    If you want only a part of the table returned either only certain columns and/or certain rows then you need to use a "select" statement of the form:
    Please Login or Register  to view this content.
    The * means all fields. replace this with a list of field name if you only want some


    click on the * Add Reputation if this was useful or entertaining.

  11. #11
    Registered User
    Join Date
    02-28-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Pull data from Access

    Thanks guys for the code...The code works perfectly fine.
    My only query here is .I will provide the user with some options in excel sheet such as data validation.

    So he will
    Select a Start date in Cell A1 of Excel Sheet1.
    Select a End date in Cell A2 of Excel Sheet1.
    Select a Location in Cell A3 of Excel Sheet1.

    My Query should pull data based on the above.

    Logic wise i am clear . Putting this in VBA is kind of difficult for me.

    Thanks once again

  12. #12
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Pull data from Access

    Quote Originally Posted by sujitshukla View Post
    Thanks guys for the code...The code works perfectly fine.
    My only query here is .I will provide the user with some options in excel sheet such as data validation.

    So he will
    Select a Start date in Cell A1 of Excel Sheet1.
    Select a End date in Cell A2 of Excel Sheet1.
    Select a Location in Cell A3 of Excel Sheet1.

    My Query should pull data based on the above.

    Logic wise i am clear . Putting this in VBA is kind of difficult for me.

    Thanks once again
    As you say you are clear on the logic I presume that you are having problems getting the cell values into the SELECT statement.

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    02-28-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    18

    Pulling data from Access

    Hi Friends,

    Need help from you all for the below mentioned Query.
    When i am trying to extract data in excel from acess, I am getting a "Data Mismatch error". Can you suggest what is causing this.

    There are 4 fields in access table Name (text), Date (date/time), Locatin(text) and Sr No.

    Please Login or Register  to view this content.
    Your help much appreciated.

  14. #14
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Pull data from Access

    You don't say where you are getting the error.
    I would expect it to be because the data in the cells does not match the format required by the select statement.

  15. #15
    Registered User
    Join Date
    02-28-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Pull data from Access

    Hi Tony,

    Thanks for the prompt response. First thing is i am new to VBA . When i execute the query doing F8, the Select statement gets executed. the next line where i open the recordset i get an error there. I checked the format of cells in access and excel and it is the same. date format for date and text format for location.

    Sujit

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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