Help with VBA\MySql statement

shabbaranks

Registered User.
Local time
Today, 07:32
Joined
Oct 17, 2011
Messages
300
Hi guys,

One thing that I am determined to master is using VBA to query with mysql, I know it can be done creating a query and I have done so and then tried to convert that to vba\mysql but it doesnt work. Im guessing its because Ive got my code incorrect - could anyone shed some light on whats incorrect with this statement please?

Code:
Dim MySql As String
 
MySql = "SELECT TimesheetTable.sUser, TimesheetTable.[Task Date], TimesheetTable.Activity, TimesheetTable.Project, TimesheetTable.Hours, TimesheetTable.Description, TimesheetTable.sCostCode FROM TimesheetTable_"
MySql = "WHERE (((TimesheetTable.sCostCode) Like [MD-LAB])) OR (((TimesheetTable.sCostCode) Like [MT-LAB]))"

Ta muchly
 
Actually, I think its been mentioned before about using a select statement within VBA - would the better method be to use a query?
 
Code:
Dim MySql As String
 
MySql = "SELECT TimesheetTable.sUser, TimesheetTable.[Task Date], TimesheetTable.Activity, TimesheetTable.Project, TimesheetTable.Hours, TimesheetTable.Description, TimesheetTable.sCostCode FROM TimesheetTable_"
MySql = "WHERE (((TimesheetTable.sCostCode) Like [MD-LAB])) OR (((TimesheetTable.sCostCode) Like [MT-LAB]))"

Hi,

i assume this is to be 1 full SQL statement. The first thing you need to do is to add the lines together. you current code set MySQL as one statement then it overwrites with the second line statement. it should look like this-

Code:
Dim MySql As String
 
MySql = "SELECT TimesheetTable.sUser, TimesheetTable.[Task Date], TimesheetTable.Activity, TimesheetTable.Project, TimesheetTable.Hours, TimesheetTable.Description, TimesheetTable.sCostCode FROM TimesheetTable "
MySql & MySql = "WHERE (((TimesheetTable.sCostCode) Like [MD-LAB])) OR (((TimesheetTable.sCostCode) Like [MT-LAB]))"

as a quick tip, you could open a new query and paste the SQL only code into it to see if it works. Also, there are many ways to execute an SQL query

Which method are you attempting in order for us to give further help?


cheers

Nidge
 
Agree with Nidge, but you'll have to check your Like conditions
 

Users who are viewing this thread

Back
Top Bottom