+ Reply to Thread
Results 1 to 9 of 9

VBA to search number/text and pull information from access into excel

  1. #1
    Registered User
    Join Date
    06-22-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2003
    Posts
    13

    VBA to search number/text and pull information from access into excel

    Not sure if I have the right forum here, so sorry if this should go somewhere else.

    I am not sure how to program a macro to search for a cell if that cell is a text cell, ie if the cell 00-DIV-00443 (a barcode)

    The hope is to move towards autoreporting. The user inputs the barcode at the start of the process and the macro runs and pulls back the data that corresponds to that barcode from access.

    I have attached a folder Data Pull.zip with a pretty Explanatory excel file and a database to practice on. The real database is much larger than the one in the folder but the code should be the same.

    Any help would be appreciated.

    Stephen

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: VBA to search number/text and pull information from access into excel

    Hi Stephen and welcome to the forum,

    It seems to me you should build relationships in your Access database to tie your tables together. Then you need to build a query with a parameter of the barcode you want, using Access. Then using Access you can use this query to export an Excel workbook. It seems to me you can really do all the work using Access and then just look at it using Excel, after an Access export to Excel.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    06-22-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VBA to search number/text and pull information from access into excel

    Marvin, I'm not much good with access and the idea was to type a barcode into excel then hit run macro and the report would autogenerate from that. I can't seem to get the coding right to retrieve the barcode data. Any ideas?

    I keep getting error copying data when I try to run a macro for the first barcode part.
    Last edited by stephen11; 06-23-2012 at 12:19 PM.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: VBA to search number/text and pull information from access into excel

    Hi,

    I understand that you aren't good with Access yet, but it is the best tool for your problem. See the attached where I tried to make a PT from your data using Excel on the Timetables sheet. The values always come out numbers, because it is in Excel, and not what you want. Then look at the 3rd sheet where I've put a picture of what Access can do for you. Access allows text to be in the values area and perfect for what you are trying to do, in my humble opinion.

    You are trying to get an output that is very complicated to do with Excel but a snap if you use Access.
    Last edited by MarvinP; 06-23-2012 at 06:32 PM.

  5. #5
    Registered User
    Join Date
    06-22-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VBA to search number/text and pull information from access into excel

    Marvin,
    There is none of my data on the timetables sheet
    My data was in this file, Data Pull.zip perhaps you uploaded the wrong file?

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: VBA to search number/text and pull information from access into excel

    Hi Stephen,

    I do believe I attached the wrong file. I will remove the attached file as it was another problem. I didn't mean to attach an answer but just suggest you do the whole problem using Access and then export an Excel workbook from it.

  7. #7
    Registered User
    Join Date
    06-22-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2003
    Posts
    13

    VBA code not retrieving any data

    I have written some code to start retrieving using VBA but it only returns the column headers and not any data, i'm not sure why
    Last edited by stephen11; 06-23-2012 at 07:02 PM.

  8. #8
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: VBA to search number/text and pull information from access into excel

    Hi, Stephen11. I added some relationships in your database and tried to get the data using ADO. Unzip the file and database in a separate folder.

    PS This is my first experience of ADO + Access, but seems it works.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    06-22-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VBA to search number/text and pull information from access into excel

    It works very well. I managed to find a solution last night that works for the whole process, barcode retrieves site code, which retrieves plant code and then retrieves the results.

    However this was on a test database that only showed a very small fraction of the real thing. My other problem is that the table named SAMPLE actually requires a log in and password on the real database. And I am not sure how to program this into the macro. Do you think it is possible?

+ 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