Getting Error Runtime Error 3156

bluestuck

New member
Local time
Yesterday, 18:03
Joined
Apr 16, 2014
Messages
9
hii everyone,

I got error runtime error 3156 when i delete it. i'v tried to this code, but i got the same errors message.

Code:
Dim strSQL As String
    
    
    strSQL = "DELETE FROM " & Table & " where [_date] between #" & Form_frm_dbo_cfa.cmbdate1.Value & "# and #" & Form_frm_dbo_cfa.cmbdate2.Value & "#"
    
    
    DoCmd.SetWarnings False
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings True

Code:
Dim strSQL As String
DIM db as Database  
    
    strSQL = "DELETE FROM "  & Table & " where [_date] between #" &  Form_frm_dbo_cfa.cmbdate1.Value & "# and #" &  Form_frm_dbo_cfa.cmbdate2.Value & "#"
  
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)

Does anyone knows how to fix it ?
Thanks a lot
 
I think you are missing the "*":

strSQL = "DELETE * FROM " & Table & " where [_date] between #" & Form_frm_dbo_cfa.cmbdate1.Value & "# and #" & Form_frm_dbo_cfa.cmbdate2.Value & "#"
 
This is not the recommended way reference a control on a form.
Form_frm_dbo_cfa.cmbdate1.Value

It should be referenced via the Forms collection:
Forms!frm_dbo_cfa.cmbdate1

Or, if the code module is on the same form:
Me.cmbdate1

(The .Value is optional in VBA because Value is the default property of a control.)
 
yes, i'v tried to use (*) but still giving me an error and i'v been looking for they said to remove it and still giving me an error. What must i do ?

Galaxiom : Thanks for your info, i just begin it. And its really usefull. I'v changed it but still giving me an error :'(
 
Hmm, you don't really have a table named *Table* do you? If you do you're going to need to change that. You'll need to change it even if you are decalring it, it's a Reserved Word. For a complete list see...

http://allenbrowne.com/AppIssueBadWord.html

In the meantime try...
Code:
strSQL = "DELETE * FROM Table WHERE [_date] between #" & Form_frm_dbo_cfa.cmbdate1 & "# and #" & Form_frm_dbo_cfa.cmbdate2 & "#"

Though I'm thinking that might not have worked because Error 3156 is related to deleting database on an SQL Server. If that is true make sure you have DELETE persmissions on the Server. If that is the case you have to change the statement to something like...

Code:
strSQL = "DELETE FROM Table WHERE [_date] between #" & Form_frm_dbo_cfa.cmbdate1 & "# and #" & Form_frm_dbo_cfa.cmbdate2 & "#"
 

Users who are viewing this thread

Back
Top Bottom