Results 1 to 2 of 2

Thread: Compile error in Access

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    11

    Compile error in Access

    Can anyone tell me what I am doing wrong in the following code?
    I get this error when I try to run the following code:
    Compile error:
    Expected Function or variable

    and the Execute method is hilighted (shown here in blue). I used the method browser to select the Execute method, so it shouldn't be mis-spelled.

    Code:
    Private Sub Form_BeforeInsert(Cancel As Integer)
        Dim db1 As Database
        Dim rs As Recordset
    
        Set db1 = CurrentDb
        
        Set rs = db1.Execute("ListItemQuery")
        MsgBox "database: " & db.Name & vbCrLf & "  max item number: " & rs.maxoforderid
    End Sub

  2. #2
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    You can only execute insert, append, and delete sql statements. It looks like you're trying to use a select statement in which case you would be better off using:
    VB Code:
    1. set dbase = currentdb
    2. set recset = dbase.openrecordset (strSql,dbOpenSnapshot)
    3. 'insert your code
    4. dbase.close
    5. set dbase = nothing
    6. set recset = nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width