Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When checked, move to table

Status
Not open for further replies.

valgore

Technical User
Nov 12, 2008
180
US
I have a table with a field called CheckBox. it has a checkbox in it. i want to say if it is checked, then import 3 other fields into a different table. so far i have

Code:
Private Sub CheckBox_Click()
On Error GoTo Err_SomeName
DoCmd.RunSQL "INSERT INTO TestCheckboxtable SELECT [AmexCurrent]![Merchant Name/Location] as [Merchant Name/Location], [AmexCurrent]![Carholder Name] as [Cardholder Name], [AmexCurrent]![CheckBox] as [CheckBox] FROM AmexCurrent WHERE Trim([AmexCurrent!CheckBox!] & '')<>''"
Exit_SomeName:
    Exit Sub
Err_SomeName:
     MsgBox Err.Number & Err.Description
     Resume Exit_SomeName
End Sub

but nothing is happening. any help would be appreciated
 
How about

If YourFormName.Checkbox=-1 then
docmd.runSQL
end if
to replace the where statement.
 
still nothing. i tried changed the -1 to a 1 and a yes, and still nothing went.

valgore
 
WHERE Trim([AmexCurrent!CheckBox!]
Does your field name REALLY contain an exclamation point?

CheckBox is a reserved word. You really should find something else.


Randy
 
no. but i thought that was the syntax. i have another process that does exactly what this does, and that works. but i can't seem to figure out why this isnt working. i changed the field to ChexBox and it still didnt work
 
Have you tried to use a breakpoint in your code so you can step through to find your issue?
I prefer to be explicit with the field names. Are your field names spelled correctly?
Code:
Private Sub CheckBox_Click()
On Error GoTo Err_SomeName
Dim strSQL As String
strSQL = "INSERT INTO TestCheckboxtable ([Merchant Name/Location], [Cardholder Name], [CheckBox]) " & _
  "SELECT [Merchant Name/Location], [Carholder Name], [CheckBox] " & _
  "FROM AmexCurrent WHERE Trim([CheckBox] & '')<>'' "

DoCmd.RunSQL strSQL

Exit_SomeName:
    Exit Sub
Err_SomeName:
     MsgBox Err.Number & Err.Description
     Resume Exit_SomeName
End Sub

Duane
Hook'D on Access
MS Access MVP
 
i tried your code Duane and when i clicked it, it gave me a parameter value input msgbox
 
i fixed that part already Randy. and i did set a break point. i set it on the DoCmd.RunSQL and i didnt get anything.
 
What is the value of strSQL prior to attempting to run the sql? When the code stops, open the debug window and enter:
Code:
? strSQL
"checkbox" generally suggests a yes/no datatype. What is the datatype of your field?

What is your current code?


Duane
Hook'D on Access
MS Access MVP
 
ok my current code is
Code:
Private Sub ChexBox_Click()
On Error GoTo Err_SomeName
Dim strSQL As String
strSQL = "INSERT INTO TestCheckboxtable ([Merchant Name/Location], [CategoryCode], [ChexBox]) " & _
  "SELECT [Merchant Name/Location], [CategoryCode], [ChexBox] " & _
  "FROM AmexCurrent WHERE Trim([ChexBox] & '')<>'' "

DoCmd.RunSQL strSQL

Exit_SomeName:
    Exit Sub
Err_SomeName:
     MsgBox Err.Number & Err.Description
     Resume Exit_SomeName
End Sub

i got it so when i check the checkbox, it says do you want to append "X" number of rows. but it wants to append all the rows. so now i need to let it know to only copy the ones with the checkbox's checked. also, can this be done in the background without having the append window pop up? i dont want the data to be moved to the other table, i want it to copy. this whole thing is to make sure an automatic query is working correctly.
 
Code:
strSQL = "INSERT INTO TestCheckboxtable([Merchant Name/Location],CategoryCode,ChexBox)" & _
  " SELECT [Merchant Name/Location],CategoryCode,ChexBox" & _
  " FROM AmexCurrent WHERE ChexBox=True"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
yeah, i was getting to it dhookom. sorry. my boss called me into his office and i wanted to submit as much as i could before i went in. the field is a yes/no. and i tried your code PHV and its still copying everything in the table over and making all the checkbox's checked
 
If the code is copying all records, then the ChexBox field for every record in the AmexCurrent table must be checked.

Set a breakpoint after the strSQL has been given a value so you can use the immediate window to grab the value. Then open a new, blank query and paste the strSQL value into the SQL view. Go to the datasheet and design views to see what's happening.

Duane
Hook'D on Access
MS Access MVP
 
ok dhook, for you first statement, what it does when i check the checkbox on the form, it copies all the records in AmexCurrent and moves them to the other table and then makes all the check boxes checked. so yeah, i dont know why its doing that. and for the breakpoint, i put it at the strSQL statement, and i didnt get anything in the immediate window when i ran it, and i also put a breakpoint at the DoCmd.RunSQL strSQL and i didnt get anything either. so i probably doing something wrong here....

Valgore
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top