473,387 Members | 1,785 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,387 software developers and data experts.

Using VBA to Update an checkbox

Hello,

I am new to this posting stuff, but here is my current dilema . . . .

I have a checkbox in one of my tables and I need for it to update using an update query. Now using straight Access I can just say UPDATE tblname.checkboxfiled=Yes or even -1 and I get the good result.

The problem is I am using ome VBA coding and it doesn't seem to like the =Yes or =-1. I tried putting them in single quotes and I get a data conversion error.

My code is as follows:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdRoleExists_Click()
  2.  
  3. Dim DB As DAO.Database
  4. Dim qdf As DAO.QueryDef
  5. Dim varItem As Variant
  6. Dim strCriteria As String
  7. Dim strSQL As String
  8.  
  9. Set DB = CurrentDb()
  10. Set qdf = DB.QueryDefs("qrySAPSecurityRoleExistsUpdate")
  11.  
  12. For Each varItem In Me!lstSecuritySAP.ItemsSelected
  13.     strCriteria = strCriteria & "," & Me!lstSecuritySAP.ItemData(varItem)
  14. Next varItem
  15.  
  16. If Len(strCriteria) = 0 Then
  17.     MsgBox "You must select at least 1 SAP #" _
  18.             , vbExclamation, "No Selection Made"
  19.     Exit Sub
  20. End If
  21.  
  22. strCriteria = Right(strCriteria, Len(strCriteria) - 1)
  23.  
  24. strSQL = "UPDATE tblTrackingData SET tblTrackingData.[SAP Security Role Status] = 'Completed - ' & Date(), tblTrackingData.[SAP Security Role] = Yes" & _
  25. "WHERE tblTrackingData.[SAP #] IN(" & strCriteria & ")"
  26.  
  27. qdf.SQL = strSQL
  28.  
  29. DoCmd.OpenQuery "qrySAPSecurityRoleExistsUpdate"
  30.  
  31. Set DB = Nothing
  32. Set qdf = Nothing
  33.  
  34. End Sub
  35.  
When I remove the tblTrackingDAta.[SAP Security Role] = Yes part of the code (which is the checkbox field) the rest works just fine.

Any thoughts would be most appreciated.

Thanks!
Mar 4 '08 #1
5 5378
Scott Price
1,384 Expert 1GB
Try using True instead of Yes.

Regards,
Scott
Mar 4 '08 #2
Thank you for your response.

When I change the last part of the code to tblTrackingData.[SAP Security Role] = True" & _ I get the same error message as when I have Yes or -1 in there.

the message is this . . . . .

Run-time error '3705':

Syntax error (missing operator) in query expression 'TrueWHERE tblTrackingData.[SAP #] IN(7397)'.

When I put single quotes around the True or Yes ot -1, This message does not appear but I get teh conversion type error.

However, on a whim I tried it with Parentheses . . . tblTrackingData.[SAP Security Role] = (Yes)" & _ and to my surprise it worked like a charm.

Thanks for your efforts and this can be closed!!!
Mar 4 '08 #3
Scott Price
1,384 Expert 1GB
That is indeed strange... I've never seen the parentheses needed in just that way, but if it's working for you, I'm glad to hear it!

Thanks for posting back with the solution.

Regards,
Scott
Mar 4 '08 #4
NeoPa
32,556 Expert Mod 16PB
Please look at lines #24 & #25 in the code you posted. You will notice if you look, that there is no resultant space before the "WHERE" clause starts (line #25). Therefore, you are actually trying to set the field to a value of YesWHERE!
This won't generally work.
This is a very common problem when building strings of SQL in VBA.
Mar 6 '08 #5
NeoPa
32,556 Expert Mod 16PB
By the way, it's always a good idea when posting code to quote the line number(s) where the error occurrs. It's so much easier to work with, therefore more likely to find an answer.
Mar 6 '08 #6

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

Similar topics

7
by: Gary | last post by:
I haver a table of students - Say 100 students that I need to be able to update/delete and amend. I know I can do this one student at a time which is simple but lets say I want to see all the...
2
by: Olivia Towery | last post by:
SQL 6.5 Database I have a list of registrants and I want to use a check box after each record to show those who attend and then post all with one submit button. Any help is appreciated. --...
2
by: Nu2ASP.NET | last post by:
What I am trying to do is essentially 'flip' the bits, when the user clicks in the checkbox. For example, if the CheckBox appears checked, and the user un-checks it, I want the underlying data...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
3
by: mountain.dog | last post by:
I have a query that shows a list of options that a user can toggle on or off using a checkbox. query... form... while($row = mysql_fetch_array($result))... <input name="menu_show_attribute"...
10
by: chimambo | last post by:
Hi All, I have a little problem. I am retrieving records from a table and I want to update the records using checkboxes. I am able to display the database record quite alright and I have created...
11
by: TechnoAtif | last post by:
INSERT AND UPDATE MULTIPLE CHECKBOX DATA USING PHPMYSQL OR JAVASCRIPT Hi All I want to check the multiple checkboxes update them after revisiting that page. I am taking the name as...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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
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...

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.