473,491 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VBA code to update tables through check box?

33 New Member
Hello,

I have this form in my database.

https://lh4.googleusercontent.com/DZ...J3wWgo7mjU8rpA

I need to figure out how to write the code for a button at the bottom of the checkboxes so that when clicked...

1) the check boxes that are selected will update in the master table, delete out of the audit table, and remain the same in the replica table

2) the check boxes that are not selected will still have the current field data and will not make a change to the tblMaster but will revert tblMasterReplica back to what it was prior to the change



Additional Background Info:

- I have a form to change view the records out of the tblMaster that is locked from editing. This is used by all the other non-Admin users.

- I have another form that can be used to submit a change request to one of the records (looks like the display form except it is not locked).

This information is then moved into tblMasterReplica (does not show in the view form). It is also displayed in the audit table to show who made the change, what time it was made, & what it was changed from and changed too (new record is on top of the other in table).

- The audit form is what is displayed on the "Updated" column in the screenshot and the tblMaster is what is displayed in the "Current" column of the screenshot.

- The screenshot is only one tab from the form, I used the tab control because there are about 65 fields for each record.


I have really been struggling with this code for quite a while and would really appreciate any additional help. I am very new to access so my background with code is extremely limited. I am very thankful for any of the help I can get.

With Appreciation,

Rob
Jul 31 '12 #1
14 5277
Seth Schrock
2,965 Recognized Expert Specialist
Your link doesn't work.

I believe that what you need is an update query. You would just have the criteria be that the check box is checked and then you would need a field that would identify which records lined up to which records in the two tables.

Without more detailed information of the table designs, it is hard to be more specific.
Jul 31 '12 #2
zmbd
5,501 Recognized Expert Moderator Expert
Good Morning Rob:
As noted, your link comes up as 403-forbidden.

Building on what Seth has pointed out...
What I would do is use a "For Each" statament to step thru the controls in the form either checking for type or name with a "Select-Case" to build my SQL string. Alternatively, if you only have two or three controls, you could just check the controls in question... just depends on the form design.

Once the SQL is built, use it as the basis for an "dbs.execute UPDATE...(remainder of SQL)"

Finally, so that you can really get the help you need, and the other experts, mod, and users can follow what you’re asking in the future, the following are really a must read:
How to ask good questions
Posting guidelines

I also highly recomend the following site as it has a great basic tutorial on RDMS design as most textbooks really do a poor job... A Tutorial for Access

Of particular note is tables page within the tutorial - notice the information that is given, the table name, the field name, the field type, key or index, etc... AND the format used to present that data. You don't need a fancy gridded table to do this... just a line by line layout. This same information is needed when talking about forms etc...

Most Respectfully
-Z
What do you mean it's still 95 outside... it's 3am!>.... oh... time for a nap :)
Aug 1 '12 #3
robtech4
33 New Member
Try clicking on the link a second time after the error comes up, for some reason that seems to work. Also, I am working hard to get through tutorials so I can better understand the answers and post better answers, zmbd. I apologize if the question was poorly written.

Thanks,

rob
Aug 1 '12 #4
Seth Schrock
2,965 Recognized Expert Specialist
The link still didn't work for me.
Aug 1 '12 #5
robtech4
33 New Member
Seth,

Please tell me what type of detailed information would help you help me. I don't want to type a bunch of useless information and have you waste your time reading it but would really appreciate the advice.

Thanks
Aug 1 '12 #6
robtech4
33 New Member
Hopefully this is not too hard to see
Attached Images
File Type: jpg screenshot1.jpg (63.3 KB, 538 views)
Aug 1 '12 #7
Seth Schrock
2,965 Recognized Expert Specialist
Okay, that helps a lot! I wasn't picturing each field having its own checkbox. So would I be correct in assuming that you would only be looking at one record when you clicked the button to make the changes?
Aug 1 '12 #8
robtech4
33 New Member
That would be correct. Everything in the left column comes from the same table and everything in the right column comes from a seperate table (they are updated changes made my non-admin users.
Aug 1 '12 #9
Seth Schrock
2,965 Recognized Expert Specialist
Okay. For ease of explanation, what is the name of the upper left-hand textbox control and the checkbox to its right? I will be able to give you the code for that one control and you can then expand it to do the rest of the controls.
Aug 1 '12 #10
twinnyfo
3,653 Recognized Expert Moderator Specialist
Rob,

The basics for the approval should work with code below. Modified to fit the controls on your form....

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub cmdApprove_Click()
  5.     If Me.chkPlantManager Then
  6.         Me.txtPlantManager = Me.txtReplicaPlantManager
  7.     End If
  8. End Sub
  9.  
Hope this helps.
Aug 2 '12 #11
robtech4
33 New Member
So I was able to get the code going to compare old data with new data thanks to your help! My new and what seems to be my last issue (hopefully) is approving the addition of a new supplier.

I have a seperate form in which you can add additions (new supplier) and then once you select "Submit Request" it updates into the replica table.

Then, when I go to the form to approve/deny the changes that others have made...the New Supplier does not populate for approval. I would suppose its because it has no record with an identical primary key in the Master List.

Is there a solution to this or will new suppliers have to be added manually into the Master Table by the Admin?

Thank you!
Aug 8 '12 #12
twinnyfo
3,653 Recognized Expert Moderator Specialist
Rob,

Create a separate form for approving new suppliers. The replica table could also have a Yes/No field flagging whether it is a new supplier. The new form would filter out only the new records.

Hope this helps!
Aug 8 '12 #13
robtech4
33 New Member
Greg,

I have a seperate form for the approval process but the master table fields are coming up as #Name? rather then blank.

--When we check the chkbox to approve each field and then select the Approve button...the record is NOT being written into the fields and therefore into the Master Table.

Please advise :)
Aug 8 '12 #14
twinnyfo
3,653 Recognized Expert Moderator Specialist
Rob,

Perhaps.... Use nearly an identical form as for the update approvals. However, for the master form, set the Data Entry Property to True, this way, it will automatically go to a new record. The subform would just filter the New records. Remove the Master/Child relationship between the two forms, so the master is not looking for some sort of relationship.

The same code should work to add the data to the master table. However, be sure that after you complete the update that the master form moves to a new record, otherwise any other updates will be overwritten.

I hope this helps.....
Aug 8 '12 #15

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

Similar topics

5
2339
by: A.Dagostino | last post by:
hi i need to update an SQL Table when user select or unselect a checkbox control. How Can i do? Thanks Alex
1
3072
by: Pesko S | last post by:
Hi, Could anybody just point me in a direction where I can find information on how the heck I can update a database with relational data from an XML file. I use stored procedures to insert...
4
3261
by: Terry | last post by:
Hello, I am designing a form from scratch and need to know how to get a Check Box(PASS)to automatically update when the data in a Text Box (MARK), in the same form, is >=24. Using the Event...
0
1042
by: ANSWER | last post by:
Hi, I have database with 20 tables, CODE (long integer)is primary key for all of them but half of the tables is linked indirectly to the main tables CODE. That works great until I had to change...
3
10946
by: wildbill | last post by:
I have an Excel spreadsheet with 1000+ rows that I need to import into an Access 2002 db once a month or so. I then need to use that information to update any existing records(multiple fields may...
4
2180
by: Jozef | last post by:
Hello, I'm trying to check for and add a field to a table to a back end database through code. The problem I've been faced with is changing permissions, because I have to use administer...
2
4404
by: Ivan | last post by:
Hi to all !!! I am new working with DB2. I have one table with 4 primary key (CLIENTID, TIMESTAMP,ENTITYTYPE,ENTITYID) and I need update this table (HISTORY). First I drop the Primary Key,...
4
1858
by: Farraige | last post by:
Hi I need your help... I am implementing the method that updates given table (table is represented as list of lists of strings) according to other table (some kind of merging)... This method...
6
2727
by: Gari | last post by:
Hello everyone, I have two forms: FORM1 and FORM2. On FORM1 there is a check box (CHECK). When CHECK is checked, the data is updated in a YES/NO data type table (TABLE) field. On FORM2 I...
1
1228
by: SKODA | last post by:
Hi, Could someone help me in knowing how to update tables in MS Access with data available on a website? I mean the functionality similar to refresh available in MS EXCEL where the data is...
0
7115
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
6978
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
7154
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
6858
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
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5451
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,...
1
4881
isladogs
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...
0
4578
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
1392
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 ...

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.