473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Please, Need help with this Dynamic SQL Code...

matrekz42
Hello friends,

I'm trying to run this Dynamic SQL in VB, but I keep getting "Compile Error" Syntax Error, in the "Bolded" area. I'm only trying to change these fields for the second query listed, should I remove the first, and repeat steps? The reason why I'm doing this, is because the table name changes from month to month. What do you Guru's recommend?




Private Sub Command0_Click()
' Declare DAO
Dim qdfCurr As DAO.QueryDef
' Declare String Name
Dim strSQL As String
' Generation of SQL Code
strSQL = "SELECT dbo_" & Format(Date, "mmm") & Format(Date, "yy").id, dbo_" & Format(Date, "mmm") & Format(Date, "yy").priority, dbo_" & Format(Date, "mmm") & Format(Date, "yy").clss, dbo_" & Format(Date, "mmm") & Format(Date, "yy").ky, dbo_" & Format(Date, "mmm") & Format(Date, "yy").date, dbo_" & Format(Date, "mmm") & Format(Date, "yy").code, FROM dbo_" & Format(Date, "mmm") & Format(Date, "yy")
' Query Definitions will be sent to "MyQuery"
Set qdfCurr = CurrentDb.QueryDefs("Current_Month_Date")
Set qdfCurr = CurrentDb.QueryDefs("Get_Report60")
' The query definitions are equal to the String with the stored SQL
qdfCurr.SQL = strSQL
End Sub
Sep 26 '07 #1
2 1443
Hello friends,

I'm trying to run this Dynamic SQL in VB, but I keep getting "Compile Error" Syntax Error, in the "Bolded" area. I'm only trying to change these fields for the second query listed, should I remove the first, and repeat steps? The reason why I'm doing this, is because the table name changes from month to month. What do you Guru's recommend?




Private Sub Command0_Click()
' Declare DAO
Dim qdfCurr As DAO.QueryDef
' Declare String Name
Dim strSQL As String
' Generation of SQL Code
strSQL = "SELECT dbo_" & Format(Date, "mmm") & Format(Date, "yy").id, dbo_" & Format(Date, "mmm") & Format(Date, "yy").priority, dbo_" & Format(Date, "mmm") & Format(Date, "yy").clss, dbo_" & Format(Date, "mmm") & Format(Date, "yy").ky, dbo_" & Format(Date, "mmm") & Format(Date, "yy").date, dbo_" & Format(Date, "mmm") & Format(Date, "yy").code, FROM dbo_" & Format(Date, "mmm") & Format(Date, "yy")
' Query Definitions will be sent to "MyQuery"
Set qdfCurr = CurrentDb.QueryDefs("Current_Month_Date")
Set qdfCurr = CurrentDb.QueryDefs("Get_Report60")
' The query definitions are equal to the String with the stored SQL
qdfCurr.SQL = strSQL
End Sub
matrekz42

Try this:

Format(Date(),"mmm") & "" & Format(Date(),"yy")
Sep 27 '07 #2
Hello friends,

I'm trying to run this Dynamic SQL in VB, but I keep getting "Compile Error" Syntax Error, in the "Bolded" area. I'm only trying to change these fields for the second query listed, should I remove the first, and repeat steps? The reason why I'm doing this, is because the table name changes from month to month. What do you Guru's recommend?




Private Sub Command0_Click()
' Declare DAO
Dim qdfCurr As DAO.QueryDef
' Declare String Name
Dim strSQL As String
' Generation of SQL Code
strSQL = "SELECT dbo_" & Format(Date, "mmm") & Format(Date, "yy").id, dbo_" & Format(Date, "mmm") & Format(Date, "yy").priority, dbo_" & Format(Date, "mmm") & Format(Date, "yy").clss, dbo_" & Format(Date, "mmm") & Format(Date, "yy").ky, dbo_" & Format(Date, "mmm") & Format(Date, "yy").date, dbo_" & Format(Date, "mmm") & Format(Date, "yy").code, FROM dbo_" & Format(Date, "mmm") & Format(Date, "yy")
' Query Definitions will be sent to "MyQuery"
Set qdfCurr = CurrentDb.QueryDefs("Current_Month_Date")
Set qdfCurr = CurrentDb.QueryDefs("Get_Report60")
' The query definitions are equal to the String with the stored SQL
qdfCurr.SQL = strSQL
End Sub

Try knocking out double quotes for the date format values and substitute 'mmm' instead of "mmm", and similarly 'yy' instead of "yy".
Sep 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Martin Feuersteiner | last post by:
Hi! I would be grateful for any advise regarding what I'm doing wrong.. My brain is stuck. Probably some stupid simple mistake I don't see. Thanks very much for your efforts! Martin I have...
9
by: Michael Dekson | last post by:
Hello, Can I exe file made in Microsoft Visual C++ decompile into source code. If it is possibly please tell me how. Thanks
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
7
by: John | last post by:
Hi all, I need finality on this once and for all please. I have a main page which contains a couple of placeholders and within these placeholders, depending on what the user presses, I load...
118
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
5
by: Y2J | last post by:
I am working through this book on C++ programming, the author is speaking of using linked lists. He gave and example which I found confusing to say the least. So I rewrote the example in a way that...
8
by: Dip | last post by:
Hello Experts, Here is the code to flatten a PC hierarchy into a level based table. It works fine. SELECT t1.TASK_ID AS TASK_LV1, t2.TASK_ID AS TASK_LV2, t3.TASK_ID AS TASK_LV3, t4.TASK_ID AS...
2
by: Mike Collins | last post by:
I have a form where I create dynamic controls at runtime. With this, I am adding a dynamic required field validator to each control as needed, but the validators are not firing when I click submit....
8
by: | last post by:
I'm looking for some design guidance on a collection of projects I'm working on. The project involves a bunch of websites constructed out of a collection of user controls. Different user...
30
by: Alf P. Steinbach | last post by:
I once suggested in that SomeOne Else(TM) should propose a string value class that accepted literals and char pointers and so on, with possible custom deleter, and in case of literal strings just...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.