473,387 Members | 1,501 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.

Transfer Records using a checkbox as a filter

Hey Everyone and thank you looking at my problem (which is very frustrating).

I'm trying to transfer records from a table in one subform to another subform (on same form) using a checkbox as a filter:

Expand|Select|Wrap|Line Numbers
  1. Private Sub TransferAndReview_Click()
  2. Dim db As dao.Database
  3. Dim strSQL As String
  4.  
  5. strSQL = "INSERT INTO Forms![Extra Work Report Checksheet]![Equipment Input Subform1].Form[(QuantityUsed[, HoursUsed])] VALUES (QuantityUsed[, HoursUsed]) FROM Forms![Extra Work Report Checksheet]![Equipment Checksheet Table Subform] WHERE [Extra Work Report Checksheet]![Equipment Input Subform1].Form[EquipmentUsed]=True;"
  6.  
  7. Set db = CurrentDb
  8. db.Execute strSQL, dbFailOnError
  9.  
  10. End Sub

The Main form is: [Extra Work Report Checksheet]

Subforms are: [Equipment Input Subform1] & [Equipment Checksheet Table Subform]

Checkbox field is: [EquipmentUsed]


I keep getting the error "Syntax error in INSERT INTO statement" which points to 'db.Execute strSQL, dbFailOnError' and I don't understand why. Neither of the fields [QuanityUsed] or [HoursUsed] are lookup fields, etc. Could someone please help out.

Thank you
ajochung is online now Add to ajochung's Reputation Report Post
Jan 8 '14 #1
4 1077
Rabbit
12,516 Expert Mod 8TB
You can't refer to form controls in a SQL string like that. You can when defining a query using the query editor, but not in code like that.

But also, if this checkbox is unbound, there's no way for it to know which record is checked because controls on a form do not belong to a record. You would need to create a new field and bind the checkbox to that field. In which case, you won't need to refer to the checkbox control in your SQL.
Jan 8 '14 #2
Hey Rabbit,
The checkbox is bound to the field in the table. Also, do you have an alternative method to perform the transfer. I tried to get everything to transfer when a button is clicked to allow the user to make any corrections prior to the transfer.
Jan 8 '14 #3
Rabbit
12,516 Expert Mod 8TB
If it's bound to a field in the table, then use the field in the table and not a reference to the form control.

Also, I just took a closer look, you can't SELECT FROM a form, you need to SELECT FROM the table.
Jan 8 '14 #4
zmbd
5,501 Expert Mod 4TB
humor me
Insert the following after line 5 - call it line 5a for now.
Expand|Select|Wrap|Line Numbers
  1. Debug.Print strSQL
Run your code as normal

Once the error occurs,
press <ctrl><g>
In the immediates window, you will see the result of your strSQL string.
Please cut and paste it back here.
I think once you do, you'll see the error
(^_^)
Jan 8 '14 #5

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

Similar topics

3
by: Dan V. | last post by:
How can I use real SQL on a DataTable? i.e. not array of rows using a filter... as in DataTable.Select. I read at : microsoft.public.dotnet.framework.adonet "As others have posted: There is no...
1
by: P | last post by:
Hello, I am having a difficult time updating a record via a stored procedure using the gridview and sqldatasource. I cannot seem to be able to find a way to set everything up so that I can pass...
1
by: bigabytes | last post by:
I'm just learning PHP (extreme novice) and I'm struggling with deleting records using a checkbox included within each row. I have a few idea but I'm not sure if my thoughts are correct. I think I...
0
by: shark | last post by:
Hi All, i am getting the error as posted below while executing Transfer logins using Dts package - sql server 2000 standard edition Can any body help? Microsoft Windows (C) Copyright...
3
madhoriya22
by: madhoriya22 | last post by:
I have solved the problem
7
by: mukeshrasm | last post by:
hello everyone I want to delete the selected records from database using checkbox. whch is generated dyanamically and checkbox is also generated dynamically,using php. so please help me. if you...
6
by: Sheree | last post by:
I have VBA code (Access 2003) like this: Private Sub SubName() rs.Filter = "" x = msgbox("Filter cleared. Number of records: " & rs.RecordCount") rs.Filter = "SELECT * from " rs.Sort = "Field1...
13
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. ...
1
by: puneetmca | last post by:
hi...this code of deleting a record from database using checkbox is not working...echo "<td>$row</td>; echo "<td>$row</td>"; echo "<td>$row....these lines print as it is...rather then...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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.