PC Review


Reply
Thread Tools Rate Thread

From Access to Excel Question - VBA review

 
 
=?Utf-8?B?Rmlsbw==?=
Guest
Posts: n/a
 
      14th Jun 2007
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!!


 
Reply With Quote
 
 
 
 
George Nicholson
Guest
Posts: n/a
 
      14th Jun 2007
Comments inline

"Filo" <(E-Mail Removed)> wrote in message
news:08C99866-24D1-4525-9B37-(E-Mail Removed)...
> 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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
A Review question from the Microsoft book(exam 70-536) Tony Johansson Microsoft C# .NET 6 2nd May 2010 02:24 PM
windwithmefs Core i7 review Part 10 - Foxconn Flaming Blade GTI Indepth review windwithme User Reviews 3 27th Jul 2009 06:27 PM
MS Access to Excel Code Review =?Utf-8?B?Rmlsbw==?= Microsoft Access External Data 2 19th Jun 2007 07:27 PM
Word 2007- display Review/Track Change Status with Review Tab hidd =?Utf-8?B?U3RldmUzMDA=?= Microsoft Word Document Management 1 17th Feb 2007 02:30 AM
Review changes question Daniel Rimmelzwaan Microsoft Word New Users 3 29th Jan 2004 06:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:00 PM.