473,404 Members | 2,195 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,404 software developers and data experts.

Need Unbound Textbox fed from crosstab query to insert/delete table data

I have an unbound control "CC_Security_1_TextBox" that gets its data from a crosstab query tied to the form. What i need is code that would update the table "CC Security" which has two columns: User and CC Security Rule when someone changes the data on the form.


I'm using an AfterUpdate event that i haven't completed, but can't find a related topic on bytes to help me finish it, so i thought i'd ask.

I think i need the code to remember the original value so it can find and delete it because what i have so far uses the new value to find and delete, which doesn't exist. The insert part seems to be working and the requery part works as well.

Expand|Select|Wrap|Line Numbers
  1. Private Sub CC_Security_1_TextBox_AfterUpdate()
  2.  
  3. If Me.CC_Security_1_TextBox = "" Then
  4.  
  5. CurrentDb.Execute " DELETE * FROM [CC Security] WHERE User = '" & Me.User_ID & "' AND [CC Security] = '" & Me.CC_Security_1_TextBox & "';"
  6.  
  7. Else
  8.  
  9. CurrentDb.Execute " INSERT INTO [CC Security] ( [User], [CC Security Rule] ) VALUES ('" & Me.User_ID & "', '" & Me.CC_Security_1_TextBox & "');"
  10.  
  11. End If
  12.  
  13. Dim holdID As String
  14. holdID = Me.User_ID.Value
  15. Me.Requery
  16. Set rs = Me.RecordsetClone
  17. rs.FindFirst "[User ID] ='" & holdID & "'"
  18. Me.Bookmark = rs.Bookmark
  19.  
  20. End Sub
  21.  
Any help would be greatly appreciated.

Thanks,
Omar
Jul 7 '11 #1
3 2429
I've got the delete insert part working for the second half of the If statement. now i just need it to delete the current record if someone deletes the text in the box. I created a hidden field on there for the original value of CC_Security_1 from the crosstab.

How can i get it to delete if the textbox = Null or ""?

Expand|Select|Wrap|Line Numbers
  1. Private Sub CC_Security_1_TextBox_AfterUpdate()
  2.  
  3. If Me.CC_Security_1_TextBox = "" Then
  4.  
  5. CurrentDb.Execute " DELETE * FROM [CC Security] WHERE User = '" & Me.User_ID & "' AND [CC Security Rule] = '" & Me.CC_Security_1 & "';"
  6. Else
  7. CurrentDb.Execute "DELETE * FROM [CC Security] WHERE User = '" & Me.User_ID & "' AND [CC Security Rule] = '" & Me.CC_Security_1 & "';"
  8. CurrentDb.Execute "INSERT INTO [CC Security] (User, [CC Security Rule]) VALUES ('" & Me.User_ID & "', '" & Me.CC_Security_1_TextBox & "');"
  9. End If
  10.  
  11. Dim holdID As String
  12. holdID = Me.User_ID.Value
  13. Me.Requery
  14. Set rs = Me.RecordsetClone
  15. rs.FindFirst "[User ID] ='" & holdID & "'"
  16. Me.Bookmark = rs.Bookmark
  17.  
  18. End Sub
Grateful for any help...

thanks,
Omar
Jul 7 '11 #2
pod
298 100+
Thsi should be simple unless I am not understanding your re, as you get your data from your crosstab query, capture the primary key of that record(PK) then create an update query according to that PK and values in the fields
Jul 7 '11 #3
Changed the first part to an IsNull statement. now it works great!

Thanks:
Expand|Select|Wrap|Line Numbers
  1. Private Sub CC_Security_1_TextBox_AfterUpdate()
  2.  
  3. If IsNull(Me.CC_Security_1_TextBox) Then
  4. CurrentDb.Execute " DELETE * FROM [CC Security] WHERE User = '" & Me.User_ID & "' AND [CC Security Rule] = '" & Me.CC_Security_1 & "';"
  5. Else
  6. CurrentDb.Execute "DELETE * FROM [CC Security] WHERE User = '" & Me.User_ID & "' AND [CC Security Rule] = '" & Me.CC_Security_1 & "';"
  7. CurrentDb.Execute "INSERT INTO [CC Security] (User, [CC Security Rule]) VALUES ('" & Me.User_ID & "', '" & Me.CC_Security_1_TextBox & "');"
  8. End If
  9.  
  10. Dim holdID As String
  11. holdID = Me.User_ID.Value
  12. Me.Requery
  13. Set rs = Me.RecordsetClone
  14. rs.FindFirst "[User ID] ='" & holdID & "'"
  15. Me.Bookmark = rs.Bookmark
  16.  
  17. End Sub
Jul 7 '11 #4

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

Similar topics

2
by: Jeffrey Sheldon via SQLMonster.com | last post by:
I am debugging one of our programs and ran the fix in Test. I would like to compare table 1 between Production and Test. I want the query to output column 1 if Production <> Test output. What...
2
by: Jacky Luk | last post by:
Hi, I can't seem to find a way to delete all records of a table. I created my tables in MySQL Query Browser, then fill them up with VC++, but some records were incorrect, And I had to recreate the...
2
by: Trevor Davies | last post by:
I have a database which I have loaded onto our as/400 v4r5. All the tables and data have loaded successfully. I am using DB2 connect to access. I now want to delete the data in a table which is...
1
by: Learner | last post by:
Hi there, I have installed Sql server 2005 developer on my machine which already has a Sql server 2000 installed on. Now i am trying to query the Sqlserver 2005 data(Ex: from Person.Address...
2
by: jason.teen | last post by:
Hi All, I am having trouble creating a crosstab query. In my original data I have two columns, One called "Categorized" and one called "Mapped' in which those columns can hold values of "true"...
1
by: qarmoe | last post by:
Here is the db with sample data. http://download.yousendit.com/AAA18BC7520F196E I want to use qryCrosstab and table "ALL" to achieve the result that would look like this query...
1
by: steve | last post by:
I'm fairly new to Access and trying to figure out how to execute a particulary query. For example I have 2 tables named TEST and TEST1. TEST has a column labeled LETTERS with values A - Z. I want...
1
by: juls | last post by:
Hi experts: I want to seek an advice from all Access experts to give me an idea or sample program in vba or how to make crosstab query that can be printed in the report of which the outfield may...
3
by: idorjee | last post by:
Hi, Is there any way I could insert the data from my current database table to a new table in a new database easily without the need to insert them one-by-one? I'd appreciate it.
2
by: Liljg | last post by:
I am using Sql server 2005 Express edition (Need to retain Table comport Data for 15days) I am attempting to Truncate (not delete) data that is older than 15 days based on the MyDate Column within...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
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...

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.