472,782 Members | 1,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 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 2796
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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.