Need help with using command button

G

Guest

I am needing some help with getting a command button to run a query through
msquery onto a worksheet. i have a work book with 33 worksheets. the first
31 worksheets are setup to be 1 sheet for 1 day's data, worksheets are
labeled as 1,2,3,...30,31. the last two of the 33 sheets are just for
summary graphs. each sheet has the date split up into three cells, such as
April 15 2005. i have 3 workbooks setup this way, 1 for each of three
shifts. on each sheet in each workbook, i also have a cell listing what
shift that worksheet is for, as well as a cell that lists what plant it is
for (1 or 2). currenly i have a query to pull some data from an Access
database to fill in some of the columns. it looks as if i will need three
queries to get all the data i want, don't need help with that yet though...
what i am wanting to do is program a command button on each sheet to look at
certain cells on the sheet to get the date, plant, and shift numbers, then
use those parameters to run the msquery to pull the data into the worksheet,
starting at a specific cell, without the colum headers, and overwriting the
columns. any help with this would be appreciated, thanks in advance.
 
G

Guest

Try This.

Use the Macro as stated below. Offcourse Insert alle the Ranges that u need.

Then Assign the Macro to a Button as u mentioned. Then It should work fine.
Let me know!

Sub LookUp()

Private Sub Insert_Click()
Dim kRow As Long
Dim ws As Worksheet
K = Sheets("LookUp").Range("J5").Value
Set ws = Worksheets("LookUp")

'find first empty row in database
kRow = ws.Range("T1").End(xlDown).Offset(1, 0).Row

'copy the data to the database
Sheets("Sheet1").Range("A1").Copy
ws.Cells(kRow, 1).Value
End Sub
 
G

Guest

is the macro copying data from excel to the database? because i am wanting
to pull data from the database into excel, based on values in certain cells
 
G

Guest

i am getting a runtime error 9
subscript out of range

i had to add a line of 'End Sub' right after the 'Sub LookUp()' line.
otherwise it gave me another error.
 
G

Guest

In case of getting Acces Info to your Excel Sheet do the folowing:

1. Press the Macro Record button
2. Go to: Data > Get External Data > New Database Querry
3. In the Tab Databases Select "New Data Source"
4. OK
5. Give the Project a name
6. Select a microsoft Acces Driver (*.mdb)
7. Connect > Select the acces file you referred to
8. The rest should point itself out

This macro then can be used every time you want the information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top