473,378 Members | 1,394 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,378 software developers and data experts.

Complex "Insert Into" SQL Statment Using Variable Source and Poor Naming

Minion
108 Expert 100+
I hate to even post this message as I probably know the answer before I begin. Still there are several problems facing me with this particular challenge.

First though I'll goto into the overview of the problem. I need to create an append query to move the values of one table to another for monthly backups. This is not hard as I have already created an Append Query. The problem is that the table name changes monthly (destination name that is) and worse the tables are named using Natural Language so they are similar to "Entry Control List Feb 2007" etc. This of course seems to be throwing SQL off terribly if I generate it using VBA prior to execution.

What I really need is help with a SQL string that can be generated in VBA and executed. Unfortunately I have no control over the naming convention and can not alter it at this time. Below I have included the working SQL from the append query, however of course it does not work when generated in VBA.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO [Blank Entry Control Log]
  2. SELECT [Entry Control Log].*
  3. FROM [Entry Control Log]
  4. WHERE (((Month([Date:]))=Month([Entry Control Log]![Date])) AND ((Year([Date:]))=Year([Entry Control Log]![Date])));
  5.  
There is the possibility that I'm barking up the wrong tree with the SQL queries in this manner and should use a recordset to copy the value then delete it. If this is the case please someone smack me and turn me in the right direction.

Thanks in advance.

- Minion -

-- Here's to baptisim by fire --
Dec 28 '07 #1
3 2828
jaxjagfan
254 Expert 100+
I hate to even post this message as I probably know the answer before I begin. Still there are several problems facing me with this particular challenge.

First though I'll goto into the overview of the problem. I need to create an append query to move the values of one table to another for monthly backups. This is not hard as I have already created an Append Query. The problem is that the table name changes monthly (destination name that is) and worse the tables are named using Natural Language so they are similar to "Entry Control List Feb 2007" etc. This of course seems to be throwing SQL off terribly if I generate it using VBA prior to execution.

What I really need is help with a SQL string that can be generated in VBA and executed. Unfortunately I have no control over the naming convention and can not alter it at this time. Below I have included the working SQL from the append query, however of course it does not work when generated in VBA.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO [Blank Entry Control Log]
  2. SELECT [Entry Control Log].*
  3. FROM [Entry Control Log]
  4. WHERE (((Month([Date:]))=Month([Entry Control Log]![Date])) AND ((Year([Date:]))=Year([Entry Control Log]![Date])));
  5.  
There is the possibility that I'm barking up the wrong tree with the SQL queries in this manner and should use a recordset to copy the value then delete it. If this is the case please someone smack me and turn me in the right direction.

Thanks in advance.

- Minion -

-- Here's to baptisim by fire --
This should be close: tName would be a dynamic table name based on Entry Control Log Date.

Dim ELDate as Date
Dim tName as String
Dim strSQL as string

ELDate = [Entry Control Log]![Date]
tName = "Entry Control List " & Format(ELDate,"mmm yyyy")
strSQL = "INSERT INTO " & tName & _
" SELECT [Entry Control Log].*" & _
" FROM [Entry Control Log]" & _
" WHERE (Month([Date:]))=" & Month(ELDate) & ") AND (Year([Date:]))=" & Year(ELDate) & ");"
Docmd.RunSql strSQL
Dec 28 '07 #2
FishVal
2,653 Expert 2GB
Hi, Minion.

Just out of curiosity. Why do you use separate table for each month?
Dec 28 '07 #3
Minion
108 Expert 100+
Jax..

Thank you it looks like this will work or at the very least get me on point. I'll try and implement it later today.

Fish..

The reason for a table per month is the orignal designer of the database chose to do montly archives using this method. Unfortunately the entire database was written as the individual taught themselves A97. Leaving the DB to be full of terribly named tables (they all have spaces in the name), no normalization, and a general lack of any automation or reports. As I'm the low man on the totem pole I am unable to make any fundamental changes to the DB at this time and until the new contract is signed I can't switch the services to my own DB that I've been writing.

Or I could have summed all that up in about 5 words.... "I work for the government". That should explain the lack of logic.

Thanks for the help

- Minion -
Dec 31 '07 #4

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

Similar topics

9
by: Luc Dal | last post by:
Hello, I've serious problem using ASP under WindowsXP sp2. I get the following reply (sorry it's in french) Erreur de compilation Microsoft VBScript error '800a0401' Fin d'instruction...
4
by: Thomas R. Hummel | last post by:
Hello, I am writing a stored procedure that will take data from several different tables and will combine the data into a single table for our data warehouse. It is mostly pretty straightforward...
6
by: Rich | last post by:
Hello, I have to create a table in an Access mdb (remotely) on the fly. Create Table tbl1(fld1 Integer, fld2 varchar(10), fld3...) Then I have to insert data: Insert Into tbl1 Values(" &...
2
by: Denis Correard | last post by:
I have an application that create an insert statment on the fly (it would be to complex to create stored procedures for all senarios) like: insert into Table (field1, field2,field3 ,field4 ) VALUES...
0
by: David Veeneman | last post by:
Is there any way to modify what gets inserted when the "Insert standard items" is selected on a tool strip? Right now I have a form with my standard menu setup saved as a template, but I'd like...
13
by: shankindc | last post by:
Hi, I have a data entry form which opens default values each time the form is open. Requirement is that users can edit existing data in the form. When the form is closed, it shouldnt update the...
1
jhardman
by: jhardman | last post by:
I know this question deals with a lot of SQL, but I am applying it to ASP, so I think this is the best place for it. When I learned SQL, I saw the "insert" command as very useless. It tries to do...
6
by: ewpatton | last post by:
Good day, I've been trying to work with SQL and an Access database in order to handle custom user profiles. I haven't had any trouble reading from my database, but inserting new entries into...
2
by: paulquinlan100 | last post by:
Hi I'm using automation in excel to insert a lot of data into an Access DB. Its all working fine, apart from the fact that the data entry people occasionally put "n/a" in the cells instead of 0,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.