pulling access into excel

amypaulsen

Board Regular
Joined
Mar 1, 2004
Messages
114
good morning oh knowledgeable ones...

I am using a SQL statement in VB within excel to pull in a table out of access. It is currently working using the reference tblTransactions.UNIT but what i really want to reference is the query NOT the table. What would I use in the SQL statment?

As always...many thanks!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Why not build the query you require in Access?

Make sure it reurns the results you require.

Then goto View>SQL View and copy the SQL from there into Excel.
 
Upvote 0
I have done that. I built the query in Access and am trying to pull it into excel. I am only trying to pull certain data out of the query so I have to build the parameters separately in VB
 
Upvote 0
what i really want to reference is the query NOT the table

So what are you 'referencing' in Access to get the SQL the table or a query.

I don't thinnk I quite understand what you wish to do.
 
Upvote 0
I'm sorry...it's a bit confusing...

I have a report in Excel that needs to stay in Excel (clients request) but the data is housed in Access where it is updated on a weekly basis. So, I built the queries in Access so the user can update the table which will automatically update the queries. Then the user goes back to Excel and chooses the desired week and through the SQL statement written in VB in Excel, it pulls the corresponding week.

I've gotten it to pull from the query, however, I'm having problems retrieving the desired selection. Here is a copy of the statement from VB:

strSQL = "SELECT qryTransactions.UNIT, qryTransactions.'" & Cells(5, 1).Value & "' from [qryTransactions] where qryTransactions.UNIT = '" & Cells(12, 35).Value & "'"

hope this makes more sense...
 
Upvote 0
Amy

That looks fine.

What is the problem?

Check in Acces that qryTransactions is returning the correct records.
 
Upvote 0
the part I am having a problem with is:

qryTransactions.'" & cells(5,1).value & "' from...

when I run the macro, the error message I am getting is:

run-time error 3075:

Invalid use of '.', '!', or '()'. in query expression 'qryTransactions.'W48''.

So the pull is obviously recognizing what is in the cell..."W48", but it wont retrieve it from the Access database. I swear this is making me pull out the last friggin hair I have!!!! UGH!
 
Upvote 0
Check what strSQL looks like.

I don't think you need the ' single quote for Cells(5,1). I'm assuming that cell contains a field name?

Also check the data type of cell - that could be causing problems.

In fact use variables instead of the cells directly.

e.g.

valCell1 = Cells(5, 1).Value
valCell2 = Cells(12, 35).Value
 
Upvote 0
that was a fabulous idea and you were almost my hero, but I ran it and got the same error except: qryTransactions.True

I've changed the formatting to value & text just to try them both out but they are defined in Access as TEXT! Ugh...

The thing that is getting me is that it says the error is because of improper use of sytax ".", "!", or "()". Out of those items, the only thing I'm using is the period and when I remove/change it, the whole thing bombs out.

Doesn't make SENSE!

Sorry for yelling I just need someone to shoot me!
 
Upvote 0
What are the values in the cells?

What are they meant to be?
 
Upvote 0

Forum statistics

Threads
1,221,783
Messages
6,161,938
Members
451,730
Latest member
BudgetGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top