Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    May 2003
    Location
    cork, Ireland, Republic of
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error msg access 2000 vba)

    Hello I was wondering if someone could explain why I get the error "Object Variable or With block variable not set" when I run the following code:

    rst as recordset
    sqlQuery as string

    sqlQuery = "Select * From [thisTableName] where [ID] = '" & TxtID.Value & "'"
    MsgBox (sqlQuery) ' I did this to check the sql statement and its correct
    Set rst = db.OpenRecordset(sqlQuery , dbOpenDynaset) **** the error happens here when I debug
    Set db = CurrentDb

    Any ideas?
    TIA
    Sheila

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: error msg access 2000 vba)

    You use db before setting it. You must swap the last two lines:

    Set db = CurrentDb
    Set rst = db.OpenRecordset(...)

  3. #3
    Lounger
    Join Date
    May 2003
    Location
    cork, Ireland, Republic of
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: error msg access 2000 vba)

    Hans as usual you were quite right
    thanks for taking the time and for answering my post

    regards
    Sheila

Posting Permissions

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