Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default From Access to Excel Question - VBA review

Hi -

I have three questions on the following code:

querystring = "SELECT * " & "FROM `" & ThisWorkbook.Path & _
"\MYDATA`.Mytable Mytable " _
& "WHERE Mytable.Dstacctunit =" & "10010"

1) Instead of referencing a Table, can I reference a Query? If yes, does the
code need to change to recognize I want to refer to a Query instead of a
Table?
2) Do the names of the column Headers (Query or Table) have to be
contiguous, without spaces (example: DSTACCTUNIT, instead of DST ACCT UNIT)?
3) Instead of referencing the true column Names, can I reference a variable
that would include the column name? If yes, Can I then have the headers with
the spaces (DST ACCT UNIT)? Can you give me a tip on how to include the
column names in a variable?

Thank you!!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default From Access to Excel Question - VBA review

Comments inline

"Filo" wrote in message
...
Hi -

I have three questions on the following code:

querystring = "SELECT * " & "FROM `" & ThisWorkbook.Path & _
"\MYDATA`.Mytable Mytable " _
& "WHERE Mytable.Dstacctunit =" & "10010"

1) Instead of referencing a Table, can I reference a Query? If yes, does
the
code need to change to recognize I want to refer to a Query instead of a
Table?


No change is necessary.
As long as the query returns records, it acts the same as a table. (Append,
Insert, Delete queries (aka Action querues) do not return records so you
can't Select from them anyhow.)

2) Do the names of the column Headers (Query or Table) have to be
contiguous, without spaces (example: DSTACCTUNIT, instead of DST ACCT
UNIT)?


If a field name contains spaces, enclose it in brackets: [DST ACCT UNIT]
Brackets are optional for field names without spaces, but they won't hurt
anything.

3) Instead of referencing the true column Names, can I reference a
variable
that would include the column name? If yes, Can I then have the headers
with
the spaces (DST ACCT UNIT)? Can you give me a tip on how to include the
column names in a variable?


dim strField as String
strField = "[DST ACCT UNIT]"

querystring = "SELECT * " & "FROM `" & ThisWorkbook.Path & _
"\MYDATA`.Mytable Mytable " _
& "WHERE Mytable." & strField & "=" & "10010"

or

strField = "DST ACCT UNIT"

querystring = "SELECT * " & "FROM `" & ThisWorkbook.Path & _
"\MYDATA`.Mytable Mytable " _
& "WHERE Mytable.[" & strField & "]=" & "10010"


HTH


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access to Excel Question Bunky Excel Discussion (Misc queries) 2 March 1st 09 05:14 PM
Excel / Access Question Les Stout[_2_] Excel Programming 1 May 7th 07 06:29 PM
Excel vs Access what art the question? PhilMontUSDA Excel Programming 10 July 23rd 05 09:07 PM
excel review bar broke Excel Discussion (Misc queries) 2 May 5th 05 04:46 PM
Excel to Access Question Nonlinear Excel Programming 1 September 19th 03 09:46 PM


All times are GMT +1. The time now is 06:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"