473,651 Members | 2,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Call Variables stored in Table

Hey there folks,

I was wondering if there was a way to store a list of variables in a
table and then call them one at a time in some loop method.

Here's what I've got:

A table "Tab Names" with 50 values all running down the first column
named "Tabs"

I then have a snippet of VBA that executes a SQL statement to make a
table.
- The SQL has a variable in it "tName"
- The SQL is run through the execute command not DoCmd.RunSQL

Is there a way to look to the table, grab the first variable, run the
SQL with that variable, and then loop through the next 49 variables
until the last variable in the table.

Thanks in advance for you expertice,

Oct 25 '06 #1
4 4645

hm*****@hartfor d.edu wrote:
Hey there folks,

I was wondering if there was a way to store a list of variables in a
table and then call them one at a time in some loop method.

Here's what I've got:

A table "Tab Names" with 50 values all running down the first column
named "Tabs"

I then have a snippet of VBA that executes a SQL statement to make a
table.
- The SQL has a variable in it "tName"
- The SQL is run through the execute command not DoCmd.RunSQL

Is there a way to look to the table, grab the first variable, run the
SQL with that variable, and then loop through the next 49 variables
until the last variable in the table.

Thanks in advance for you expertise
Sure, not hard at all.

Public Sub ProcessSQLs()
dim rs as DAO.Recordset
dim strSQL As String

'--read the individual field values in the column...
set rs = DBEngine(0)(0). OpenRecordset(" SELECT [Tabs] FROM [Tab
Names]", dbOpenSnapshot)

do until rs.EOF
'---build SQL statement in a string variable
strSQL = "INSERT INTO... WHERE SomeField=" & cQUOTE &
rs.Fields("tNam e") & cQUOTE

'--Execute the statement
DBEngine(0)(0). Execute strSQL, dbFailOnError
'--Move to next record
rs.MoveNext
loop '---repeat with each record in the recorset

'--clean up variables.
rs.close
set rs=nothing

End Sub

Oct 25 '06 #2
The logic of what you are doing is, to say the least, "unusual." If you
explain what you have and what you are trying to accomplish, there's a
really good chance that someone will be able to suggest a simpler approach
than creating so many (temporary?) tables. At best, if you do this, you
will have to Compact and Repair frequently to prevent database bloat.

However, to answer your question: You can construct the entire SQL
statement, and probably will only need a couple of concatenations. The
"source" of a Db.Execute is a string. Here's a quick example, using a
delete query because it was simpler... you code your own loop, table read,
etc. use your own text as basis for the SQL, and retrieve your table name
from your "table of tablenames." For the query you describe, you won't need
a WHERE clause. "tblDelMe" is a little test table with a text field for
primary key.

Function ExecuteQuery(ps trK As String) As Boolean
On Error GoTo Proc_Error
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strQ As String
Dim strT As String
strT = "tblDelMe"
strQ = "DELETE * FROM " & strT & " WHERE [ID] = """ & pstrK & """"
Set db = CurrentDb()
db.Execute (strQ)
ExecuteQuery = True
Proc_Exit:
On Error GoTo 0
Exit Function

Proc_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure ExecuteQuery of Module basDAOMiscCode"
ExecuteQuery = False
Resume Proc_Exit
End Function

Larry Linson
Microsoft Access MVP

<hm*****@hartfo rd.eduwrote in message
news:11******** **************@ f16g2000cwb.goo glegroups.com.. .
Hey there folks,

I was wondering if there was a way to store a list of variables in a
table and then call them one at a time in some loop method.

Here's what I've got:

A table "Tab Names" with 50 values all running down the first column
named "Tabs"

I then have a snippet of VBA that executes a SQL statement to make a
table.
- The SQL has a variable in it "tName"
- The SQL is run through the execute command not DoCmd.RunSQL

Is there a way to look to the table, grab the first variable, run the
SQL with that variable, and then loop through the next 49 variables
until the last variable in the table.

Thanks in advance for you expertice,

Oct 25 '06 #3
Larry,

I am interested to learn of another way to minimize DB bloat. Here's a
little more background, let me know if my thinking is correct. I've
only been working with VBA for two months now.

I need to allow people who don't know how to code in VBA the ability to
change the variables in my table "Tab Names". My ultimate goal is to
create a form that would allow other Non-VBA savye employees to add or
delete companies from the table.

The table is a list of 50 or so company codes, ie WalMart. The SQL I
have takes these variables and creates andexports an Excel Worksheet
with the worksheet tab named as the variable, ie Walmart. The SQL also
uses the variable to select only the records in the main table with
that name. So there's a big table with a bunch of company info, then
the SQL resultant selects only the records with that company name. It's
just a way to seperate out the data for ease of analysis.

If you folks know of a way to minimize the number of tables, and bloat
while still allowing for a end Form alteration of the variable on the
list.

I really appreicate your help her everyone, this is my number one
source for "to the point" VBA help, thanks!

Oct 25 '06 #4
Just in case any one would like to see the final solution I settled on
here it is:

Public Sub Company_Tab()
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strComps As String
Set rs = CurrentDb.OpenR ecordset("Tab Names", dbOpenSnapshot)

Do Until rs.EOF

strComps = rs.Fields("Tab Name")

strSQL = "SELECT Companies." & strComps & "INTO tbl" & strComps"

CurrentDb.Execu te strSQL, dbFailonError

rs.MoveNext

Loop

rs.Close

Set rs = Nothing
End Sub

Oct 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11452
by: Titus Cheung | last post by:
Hello, I want to write some code such that it'll update (ie insert, delete, etc) some data to/from a mySQL database whenever a user hit an HTML form button (ie Submit). Now what I find annoying is that this form can only, from my understanding, execute a separate PHP file with the <form action=removerow.php> code. Or can I call a function? The reason being I find that the form will only pass a single variable to this "removerow.php"...
7
2241
by: TinTin | last post by:
Hello, How do I concatinate a variable. Here's the scenarios: declare @var1 varchar(20) declare @var2 varchar(20) declare @var3 varchar(20) declare @var4 varchar(20) .. ..
8
2029
by: Lucas Lemmens | last post by:
Dear pythonians, I've been reading/thinking about the famous function call speedup trick where you use a function in the local context to represent a "remoter" function to speed up the 'function lookup'. "This is especially usefull in a loop where you call the function a zillion time" they say. I think this is very odd behavior.
0
7137
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE TRIGGER statement.) I've also defined a SQL stored proc, and the trigger is set to call this SP. I've posted the simplified source below. I can manually call the stored proc, and the external trigger is created without any errors. However, when I do...
1
1922
by: RSH | last post by:
Im trying to create a stored procedure of the following code. I want to set it so that I have to send the first 4 variables (@DB, @BackUpFile,@TestDB,@RestoreFile). I am having trouble when i try to save it...SQL Server wants me to decalre the variables. How would I go about making this a stored procedure correctly? Here is the code: USE master GO
10
7228
by: EOZyo | last post by:
Hi, i'm trying to set pagination for a search i run on my website, i'll try to explain the easiest i can: When i click the search button on search.php, data is received and stored in variables within results.php, MySQL structure seems to work as expected, although i get some problems: As soon as i click on the "Page 2" Link, i get nothing, neither results nor page numbers.
3
15779
by: mandible | last post by:
I'm trying to call one stored procedure inside another. I was wondering if this is possible Some ideas I was toying with is putting the first stored procedure inside of a temp table but haven't been able to get this idea to work.
1
2282
by: chaitanya02 | last post by:
Hi All, Well- this question might have appeared several times on this forum- but would appreciate your reply on this: I have a asp page, where customers login with some username and the pwd, which are stored in sql. i should be using this user name and pwd and check if it is the same as the userid and the pwd in the sql 4 table..IF so then: display the download url which is in sql3 by querying the four tables.. These four tables are...
2
2815
by: Brad Pears | last post by:
I am working on a vb.net 2005 project using sql server 2000 as the backend . I am having a bit of problems with date variables... Here is the scenario... I have a table that includes a couple "smalldatetime" fields. In my class for this table, when inserting new or saving a row in the table, both of these date values may possibly be empty. (ie I am allowing nulls on the db side... )
0
8347
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
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,...
0
8694
jinu1996
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...
0
7294
agi2029
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...
0
5605
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();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4280
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1585
bsmnconsultancy
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...

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.