Ok, I have a button on a form that I'm using to create another table I will need later in my form. I have created a reference table called Ref_Table (holds my table names - using this as the tables with the orginal data changes from project to project), I have another reference table called Ref_Fields (this holds the fields I will need to pull out of the tables they are in.)
I know there is a better way to code some of this so if you happen to have a more effective way of doing this that would be wondeful to learn as well. I have put a breakpoint when at the end to see if all my variables were populating correctly. They were. The SQL20 at the end of the code gives me the SQL statement I need and I can type this directly into an SQL windown in access and run the query without any errors and the table is created. I pasted the SQL statement at the very end to show what is being generated by the code.
Ok here is the VBA code for this button and the Ref_Table and Ref_Field
Ref_Table
Field | Data
source_zone_tab le_name | zone
source_processi ng_rule_name | processing_rule
Zone_table_name | Zones
join_system_no | system_no
Ref_Field
Field | Data
processing_fiel ds | processing_rule .zonestate_id, event_id, glsched_id, sched_no, gldisp_id, dispage_no, zone_to_restore , alt_cs_no
zone_fields | zone.system_no, zone_id, alarmgrp_no, comment, camera_zone_id
each of the above have the processing_rule . or zone. before them, just left them off for typing. -
Private Sub btnStep20_Click()
-
' Create the Zones table from the sellers MMMe processing rule and zone table
-
Dim SQL20 As String
-
Dim rs1 As New ADODB.Recordset
-
Dim rs2 As New ADODB.Recordset
-
Dim rs3 As New ADODB.Recordset
-
Dim rs4 As New ADODB.Recordset
-
Dim rs5 As New ADODB.Recordset
-
Dim rs6 As New ADODB.Recordset
-
Dim strConn As String ' stores the connection string
-
Dim srcZoneTbl As String
-
Dim srcProcessingTbl As String
-
Dim srcSystemNum As String
-
Dim srcZoneFields As String
-
Dim srcProcessingFields As String
-
Dim srcZones As String
-
-
strConn = CurrentProject.Connection
-
' set the srcZoneTbl variable to name of the table given
-
Set rs1 = New ADODB.Recordset
-
rs1.Open "SELECT source_zone_table_name FROM Ref_Data", strConn, adOpenDynamic
-
-
If rs1.RecordCount <> 0 Then
-
rs1.MoveFirst
-
srcZoneTbl = rs1("source_zone_table_name").Value
-
Else
-
Debug.Print rs1("source_zone_table_name").Value
-
End If
-
Set rs2 = New ADODB.Recordset
-
' set the srcProcesingTbl variable to the name of the table given
-
rs2.Open "SELECT source_processing_rule_name FROM Ref_Data", strConn, adOpenDynamic
-
-
If rs2.RecordCount <> 0 Then
-
rs2.MoveFirst
-
srcProcessingTbl = rs2("source_processing_rule_name").Value
-
Else
-
Debug.Print rs2("source_processing_rule_name").Value
-
End If
-
-
Set rs3 = New ADODB.Recordset
-
' set the srcSystemNum variable to the join value being used between the two tables
-
rs3.Open "SELECT join_system_no FROM Ref_Data", strConn, adOpenDynamic
-
-
If rs3.RecordCount <> 0 Then
-
rs3.MoveFirst
-
srcSystemNum = rs3("join_system_no").Value
-
Else
-
Debug.Print rs3("join_system_no").Value
-
End If
-
-
Set rs4 = New ADODB.Recordset
-
' set the array to the fields needing to be pulled from the table
-
rs4.Open "SELECT processing_fields FROM Ref_Fields", strConn, adOpenDynamic
-
Dim arrProcessingArray As Variant
-
arrProcessingArray = rs4.GetString(adClipString, , "; ", ", ")
-
arrProcessingArray = Left(arrProcessingArray, (Len(arrProcessingArray) - 2))
-
-
Set rs5 = New ADODB.Recordset
-
' set the array to the fields needing to be pulled from the table
-
rs5.Open "SELECT zone_fields FROM Ref_Fields WHERE ((zone_fields) Is Not Null)", strConn, adOpenDynamic
-
Dim arrZoneArray As String
-
arrZoneArray = rs5.GetString(adClipString, , "; ", ", ")
-
arrZoneArray = Left(arrZoneArray, (Len(arrZoneArray) - 2))
-
-
Set rs6 = New ADODB.Recordset
-
' set the srcZones variable to the name of the table being created. using a variable
-
' as we will not alwyas get the previous two tables.
-
rs6.Open "SELECT Zone_table_name FROM Ref_Data", strConn, adOpenDynamic
-
-
If rs6.RecordCount <> 0 Then
-
rs6.MoveFirst
-
srcZones = rs6("Zone_table_name").Value
-
Else
-
Debug.Print rs6("Zone_table_name").Value
-
End If
-
-
-
Me.Message = "A query will open for you to use..."
-
Me.Repaint
-
SQL20 = "SELECT " & arrZoneArray & ", " & arrProcessingArray & " INTO " & srcZones & " FROM " & srcZoneTbl & " INNER JOIN " & srcProcessingTbl & " ON (" & srcZoneTbl & "." & srcSystemNum & "=" & srcProcessingTbl & "." & srcSystemNum & ") AND (" & srcZoneTbl & ".zone_id=" & srcProcessingTbl & ".zone_id);"
-
-
'DoCmd.OpenQuery ("qryMakeZonesTablefromMMMe"), acViewDesign, acEdit
-
Me.Message = SQL20 ' normally has a phrase that the step is done, but set to this variable to see SQL statement being sent to DB
-
Me.Repaint
-
rs1.Close
-
rs2.Close
-
rs3.Close
-
rs4.Close
-
rs5.Close
-
rs6.Close
-
Set rs1 = Nothing
-
Set rs2 = Nothing
-
Set rs3 = Nothing
-
Set rs4 = Nothing
-
Set rs5 = Nothing
-
Set rs6 = Nothing
-
-
End Sub
-
SQL Statement for SQL20 -
SELECT zone.system_no,
-
zone.zone_id,
-
zone.alarmgrp_no,
-
zone.comment,
-
zone.camera_zone_id,
-
processing_rule.zonestate_id,
-
processing_rule.event_id,
-
processing_rule.glsched_id,
-
processing_rule.sched_no,
-
processing_rule.gldisp_id,
-
processing_rule.dispage_no,
-
processing_rule.zone_to_restore,
-
processing_rule.alt_cs_no
-
INTO Zones
-
FROM zone
-
INNER JOIN processing_rule ON (zone.system_no=processing_rule.system_no)
-
AND (zone.zone_id=processing_rule.zone_id);
-
Any ideas? Thanks so much in advance!!!
0 1757 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Douglas Buchanan |
last post by:
I am using the following code instead of a very lengthly select case
statement.
(I have a lot of lookup tables in a settings form that are selected
from a ListBox. The data adapters are given a similar name to the
table. Rather than making a long Select Case that could become
obsolete if lookup tables are added and the source table of the
ListBox is edited I came up with this code.)
This code works but of course it gives me build...
|
by: markydev |
last post by:
Hi,
I'm using sql server 2000 sp4.
I've 2 databases linked, an instance and my local.
I'm getting two different errors when trying to update the remote table
(local server) from the instance.
There is only one row of data in the table with an identity field.
1st sql:-
UPDATE ..dbo.NUMBERS SET =3
|
by: Kavitha Rao |
last post by:
Hi,
I am getting the following errors while trying to run this snippet
in Microsoft Visual C++.Can't seem to print the crc value stored.
/* +++Date last modified: 05-Jul-1997 */
/* Crc - 32 BIT ANSI X3.66 CRC checksum files */
#include <stdio.h>
#include "crc.h"
|
by: AndyAFCW |
last post by:
I am developing my first .NET application that connects to a SQL
Server 2000 database and I am having a total nightmare :x :evil:
I am running Windows 2000 with Visual Studio .NET version 7.0.9466,
.NET Framework 1.0.3705 and SQL Server 2000.
I have created a simple table in an SQL database. SQL server includes
ASPNET as a valid login which has unlimited access to all databases,
including the database I have created. The ASPNET...
|
by: PHP_Paul |
last post by:
Ok, I'm trying to poineer into the wonderful area of PHP/MySQL programming, but I'm having some difficulties. http://www.paulhq.com/php/freepage.html should register, but when anyone fills something out, it returns a MySQL error: Could not insert data because You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
Here are the codes:
freepage.html...
| |
by: ridergroov |
last post by:
I had this message previously in another group and I was told to try
here. Hopefully someone can help out. Site was created in Dreamwaver
MX 04 and I cna't figure out why there are so many errors or how to fix
them. Original thread can be found here:
http://groups.google.com/group/mozilla.support.firefox/browse_thread/thread/9f479425c897212b/106dbd2754e85252?q=looks+good+in+firefox&rnum=1#106dbd2754e85252
I've been working on our...
|
by: ak1dnar |
last post by:
Hi, I have created a PHP page that write down form data to mySQL table.
Before i submit data I want to check the Input field, whether it has filled up or Not.
the form should validate from the PHP itself Not from JS or any other client side scripting.
when i submit the form by using $PHP_SELF i can trap the errors, but it will delete previously entered values from the page and display empty input boxes.
So what i need to do I want...
|
by: Keith G Hicks |
last post by:
I'm having a lot of trouble with "file in use" errors in my "folder watcher"
project. Starting and stopping the watcher and reading my XML file work
fine. Once the watcher is started, I'm reading the text files from the
watched folder line by line into variables and then posting them to a SQL
table.
All of the code for the form is shown below. And it works fine except for 2
issues.
First issue: In the Finally of the Try for teh SQL...
|
by: timber910 |
last post by:
I posted this in the VB forum but I think its in the wrong place. So I thought I would try here.
_________________________________________
Ok, I have a button on a form that I'm using to create another table I will need later in my form. I have created a reference table called Ref_Table (holds my table names - using this as the tables with the orginal data changes from project to project), I have another reference table called Ref_Fields...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |