473,398 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

MS Access VBA update table on click of a button from a form

Hi everyone,

I have 2 tables Sheet1 and Sheet2. They both have identical data and contain Employee Info like name, address, ID, Division,etc. HR wants to update the info in Sheet2 using a form "Sheet2 Form" where they find the employee using ID and then update their info.

Now I have created a button that updates the Sheet1 employee info with the current record that we are viewing in Sheet2 Form. So I created a button in the form with the name "Update Record in Sheet1". On click event I wrote the following vba code

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command198_Click()
  2. Dim strSQL As String
  3. strSQL = "UPDATE Sheet1 SET Sheet1.DIVISION = " & Sheet2_subform.DIVISION & " WHERE Sheet1.Empl_ID = " & Empl_ID & ""
  4. DoCmd.RunSQL strSQL
  5. End Sub 
However this is not really working any ideas?
Thanks
Jul 1 '14 #1
7 9335
Rabbit
12,516 Expert Mod 8TB
Why do you have 2 identical tables?
Jul 1 '14 #2
I need it to be there because the process is that the changes need to be approved by the manager before they move into sheet1 but it needs to be there in sheet2 for them to be able to see what the changes are. Any ideas why my VBA code isn't running properly?
Jul 1 '14 #3
Rabbit
12,516 Expert Mod 8TB
Hard to say what's wrong, there's not enough detail.

I don't know if you're getting any error codes. I don't know what the table definition is. I don't know if your SQL runs outside of the VBA.

Without any of this info, all I can do is take a shot in the dark. It could be that a field is mispelled or a table name is mispelled. Or maybe you have conflicting data types. Or maybe a form reference is incorrect.
Jul 1 '14 #4
So exactly whats happening is that when i click the button it gives a pop-up box asking for Sheet1.DIVISION and then another for Sheet1.Empl_ID. Even after I give those the it is still not updating anything in sheet1 i get a message stating "you are about to update 0 rows".

2nd problem is that I do not want it to give pop-up boxes I want sheet1.division to be picked up as Sheet2_subform.DIVISION and sheet1.Empl_ID as the Empl_ID on the form
Jul 1 '14 #5
Rabbit
12,516 Expert Mod 8TB
When it gives you those popups, that means it couldn't find the table or the field you're referencing.
Jul 2 '14 #6
rwalle
47
If I got it right you have a employee table where you have all the employee related data in fields like Name LastName Address,StartDate,Dept. and you need to update one or more fields like position or salary rate ,as if someone will be promoted lets say from front desk to sales? is this what you want to do ?
Jul 2 '14 #7
twinnyfo
3,653 Expert Mod 2GB
Are you certain that Sheet1 has fields called "DIVISION" and "Empl_ID"? Are these both numerical values? If they are text, then try this:

Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE Sheet1 SET Sheet1.DIVISION = '" & Sheet2_subform.DIVISION & "' WHERE Sheet1.Empl_ID = '" & Empl_ID & "';"
Grasping at straws here.....
Jul 2 '14 #8

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

Similar topics

4
by: Emmett Power | last post by:
Hi, I have a small online survey in two parts designed to allow users to rank a few organisations that they have dealings with from a large list of organisations. I want the users to be able to...
2
by: Paul | last post by:
wondered if anyone might lend a hand? I'm having a little difficulty updating the backend SQL Server tables. Normally I just use Access' update but I'd really like to try something new. I'd like...
5
by: Steve | last post by:
Hi, Is it possible to make hitting the enter key in an ASP textbox run the code behind an ASP button on a form? I have a search page which users tend to type in the query then just hit enter...
2
by: JIM.H. | last post by:
Hello, I am bringing a table through a data grid. Some of the field in this data grid have nothing in it and I need users type something there and click a button to update table. Is there any...
3
by: eholz1 | last post by:
Hello PHP programmers. I had a brilliant idea on one of my pages that selects some data from my mysql database. I first set the page up to display some info and an image, just one item, with a...
5
by: g | last post by:
Hi Guys.. i know this might sound really really simple, but I'm kinda stuck..I have this form..which has a table (created from stored procedure values)..once the table is populated..i have some...
4
by: anonymous | last post by:
Hey! Im trying to use an update and continue button on a form without any javascript. so first just like a shopping cart where user update their cart so they can see the totals and then...
3
by: svgeorge | last post by:
Please tell me how to Insert Web Interface records to SQL database table on Button click I have several records for approving payment and these records needs to be inserted into a table Payment...
4
by: Light1 | last post by:
I am working in Access 2003. I have a form that pulls information from a couple of tables. When the user chooses a selection from the dropdown menu of a combo box, it is putting that information...
3
by: mandeep gill | last post by:
how to open table on button click with search creteria passed? i have a form with two text boxes for search according to name and phone number . i am opening a table on click of button. i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...
0
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
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...

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.