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!

Eror 3065, "cannot execute a select query"

Status
Not open for further replies.

sisieko

Programmer
Jun 13, 2004
56
US
I am attaching this code to the onload event of a form bound to a table.
And i want it to check a chkbox on this form if some data on this form (Text18, txtResource) exits in "another" tiny table ([Weekending], [sID]).

Here is what i have at the onload event:

Code:
On Error GoTo Err_ChkBox_Click
Dim db As DAO.Database
Set db = CurrentDb()
Dim MySQL As String, DQ As String
DQ = """"

    MySQL = "SELECT [WeekEnding] from tblNoSupportHrs WHERE [sID] = " & DQ & Me.txtResource & DQ & _
        " And [WeekEnding] = " & DQ & Me.Text18 & DQ & ";"

        If Me.Text18 = MySQL Then
            Me.chkNoSupportHrs = True
        Else
        End If
db.Execute MySQL, dbFailOnError

Exit_ChkBox_Click:
    Set rs = Nothing
    Set db = Nothing
    Exit Sub

Err_ChkBox_Click:
   MsgBox "Error No:    " & Err.Number & vbCr & _
   "Description: " & Err.Description
   Resume Exit_ChkBox_Click

End Sub


However, i get this error: When i load my form.
Any thoughts or suggestions? What am i doing wrong?

 
The Execute method of the Database object should be used for action queries only (UPDATE, INSERT, DELETE, ALTER, ...)
Either play with a Recordset or the DLookUp function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,

I have also tried the Dlookup you gave me. It does do anything. I still have it commented in my code. That's why i thot i try select again.

Code:
        If DLookup("WeekEnding", "tblNoSupportHrs", "sID=" & DQ & Me.txtResource & DQ & " AND WeekEnding=" & DQ & Me.Text18 & DQ) = Me.Text18 Then
            Me.chkNoSupportHrs = True
        Else
        End If

 
What happens if you move the DLookUp code from the Load to the Current event procedure ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I have just done that. Still nothing :(
*wipes tear

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top