473,462 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

update in multiple tables through VBA

I have around 10 tables (let's call them tblNEEDUPDATE) and each has around 10-15 fields (first field is Name, rest have numbers). Also, I have a table let's call it tblUSEINUPDATE (this also has the name column) and TOTAL column.

Basically for each tblNEEDUPDATE, I want to update all fields except for name), so that each column = column/tblUSEINUPDATE.TOTAL.

I know I can go hard way and create SQL which has individual table and column names, but I was wondering if I can use a loop to go through each table (this I know how to do through Alltables) and each field and use update sql statement.


Something like THIS


Sub test()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData

For Each obj In dbs.AllTables

BUT WHAT TO DO HERE
HOW DO i define for each column if column name <>"name" then have update statement
basically my question is how do I define field object in access?

End If

Next obj
End Sub


Thanks very much for
Jasmine
May 21 '07 #1
2 5474
Rabbit
12,516 Expert Mod 8TB
I have around 10 tables (let's call them tblNEEDUPDATE) and each has around 10-15 fields (first field is Name, rest have numbers). Also, I have a table let's call it tblUSEINUPDATE (this also has the name column) and TOTAL column.

Basically for each tblNEEDUPDATE, I want to update all fields except for name), so that each column = column/tblUSEINUPDATE.TOTAL.

I know I can go hard way and create SQL which has individual table and column names, but I was wondering if I can use a loop to go through each table (this I know how to do through Alltables) and each field and use update sql statement.


Something like THIS


Sub test()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData

For Each obj In dbs.AllTables

BUT WHAT TO DO HERE
HOW DO i define for each column if column name <>"name" then have update statement
basically my question is how do I define field object in access?

End If

Next obj
End Sub


Thanks very much for
Jasmine
Before you even do this, it's not a good idea to store calculated values like you're doing. Simply because you run into this very problem where you have to update all the tables whenever a value changes. It's better to leave it to a query to run just before you need it.
May 21 '07 #2
Before you even do this, it's not a good idea to store calculated values like you're doing. Simply because you run into this very problem where you have to update all the tables whenever a value changes. It's better to leave it to a query to run just before you need it.

thanks for your reply, I just looked in the previous responses I found an answer to my question, so my code would be like this and it worked:

Sub FieldNames()
Dim Rst As Recordset
Dim s As Field
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData

For Each obj In dbs.AllTables

Set Rst = Application.CurrentDb.OpenRecordset(obj.Name)
For Each s In Rst.Fields

Debug.Print s.Name
'will put update statement here
Next

Rst.Close

Next obj

End Sub
May 21 '07 #3

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

Similar topics

17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
1
by: Wing | last post by:
Hi all, I have created 2 tables in sql database and join these 2 tables before assign the result to the dataset, and display the result in datagrid. Everything is fine up to this point. The...
9
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
1
by: Foef | last post by:
When I have a stored procedure, with multiple tables in MS Access, in a dataset and I change it in my DataGrid, I get the next message when I want to update my DataSet: ...
1
by: CS | last post by:
I need to update multiple tables from one form using a command button. The info from the different text boxes should then go into the tables. Can someone help me with some example code on how to...
6
by: shil | last post by:
Hi, I am writing a windows app in .net 2003. I have a datagrid which gets data from a storedprocedure. My question is how can I update the data in the datagrid? I want to call another...
1
by: andrewcw | last post by:
I have just 1 table that I am updating, the SQL I use to generate the DataTable is complex using multiple tables, however when I view the fieldnames of the DataTable from the DataSet - everything...
10
by: frizzle | last post by:
Hi there, I'm building a music site with a mysql backend. It has a many to many relational database. I use this to match music genres with certain artists, to maintain the possibility to add...
4
by: dstorms | last post by:
I'm trying to run an update query on multiple tables, and since Access doesn't allow me to update tables from a union query, I'm writing a module as a workaround. So I've set up a temporary recordest...
5
by: Bogdan | last post by:
Hi, I have a stored procedure that uses JOINs to return columns from multiple tables. I also have another stored proc that that takes a series of params and updates multiple tables. I used the...
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,...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.