Results 1 to 4 of 4

Thread: ** RESOLVED **Access Query Results shown in Excel S/Sheet

Hybrid View

  1. #1
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    No problem. You don't have to set up your Access query to accept a variable. You can pass variables after the WHERE statement in the SQL when you open the query from VB. In DAO it would be something like this:

    VB Code:
    1. iRequestedWeekNo = 5
    2. sSQL = "SELECT * FROM MyQueryName WHERE ((WeekNo)='" & iRequestedWeekNo & "');"
    3.     Set rs = db.OpenRecordset(sSQL)
    It doesn't really matter whether you are using DAO, ADO, etc. Just put the criteria after the WHERE statement in an SQL to pull up the records that match that criteria.

    Then you can open a file in Excel and use the Excel CopyFromRecordset method to put your recordset data into Excel.

    Here's a hint: You don't even have to have a query in Access. You can do the whole query from VB by setting the SQL when you open the recordset. If you aren't sure what the SQL should be, create a query in Access then switch to SQL view. It will show you the SQL used to create the query. Sort of like recording a macro in Excel or Word.
    Last edited by WorkHorse; Jul 10th, 2003 at 10:07 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width