9 Replies - 1004 Views - Last Post: 22 August 2013 - 11:27 AM Rate Topic: -----

#1 sunmoon143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-August 13

"Object variable or With block variable not set"

Posted 21 August 2013 - 11:13 AM

Hi
I am getting error saying "Object variable or With block variable not set"

Set RSRegion = goCurrentDb.OpenRecordset("select distinct * from qryUserEnabledRegion where userId = '" & gsWinUserId & "' order by region")
   
   With RSRegion
      While Not .EOF
         strRegionList = strRegionList & ";""" & !Region & """;""" & !Id & """"(Getting error here saying Object variable or With block variable not set")
         .MoveNext
      Wend
      .Close
   End With


tell me where is the error and how to correct it

This post has been edited by andrewsw: 21 August 2013 - 11:24 AM
Reason for edit:: Please use CODE tags


Is This A Good Question/Topic? 0
  • +

Replies To: "Object variable or With block variable not set"

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3320
  • View blog
  • Posts: 11,227
  • Joined: 12-December 12

Re: "Object variable or With block variable not set"

Posted 21 August 2013 - 11:30 AM

I would guess that your field is named userID and not Id
Was This Post Helpful? 1
  • +
  • -

#3 sunmoon143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-August 13

Re: "Object variable or With block variable not set"

Posted 21 August 2013 - 11:43 AM

View Postandrewsw, on 21 August 2013 - 11:30 AM, said:

I would guess that your field is named userID and not Id

So i should check in Database the feild name ?
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3320
  • View blog
  • Posts: 11,227
  • Joined: 12-December 12

Re: "Object variable or With block variable not set"

Posted 21 August 2013 - 11:53 AM

View Postsunmoon143, on 21 August 2013 - 06:43 PM, said:

So i should check in Database the feild name ?

Yes, always check the field-names.

This post has been edited by andrewsw: 21 August 2013 - 11:53 AM

Was This Post Helpful? 0
  • +
  • -

#5 sunmoon143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-August 13

Re: "Object variable or With block variable not set"

Posted 21 August 2013 - 12:11 PM

View Postandrewsw, on 21 August 2013 - 11:53 AM, said:

View Postsunmoon143, on 21 August 2013 - 06:43 PM, said:

So i should check in Database the feild name ?

Yes, always check the field-names.


I have in my database , in the table i have feilds userid and id ...userid is for names and id is for regions
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3320
  • View blog
  • Posts: 11,227
  • Joined: 12-December 12

Re: "Object variable or With block variable not set"

Posted 21 August 2013 - 12:18 PM

Presumably strRegionList is a string variable?

Use Debug.Print !Region and the same, on a separate line, for !Id. Set a breakpoint by clicking to the left of a statement (in the grey bar); step through the code by pressing F8. Study other debugging techniques.
Was This Post Helpful? 0
  • +
  • -

#7 sunmoon143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-August 13

Re: "Object variable or With block variable not set"

Posted 21 August 2013 - 12:24 PM

Hi
when i am press f8 from query its directly going to error message
Was This Post Helpful? 0
  • +
  • -

#8 sunmoon143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-August 13

Re: "Object variable or With block variable not set"

Posted 21 August 2013 - 08:27 PM

from the query directly its going to errormsg
Was This Post Helpful? 0
  • +
  • -

#9 sunmoon143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-August 13

Re: "Object variable or With block variable not set"

Posted 22 August 2013 - 06:13 AM

View Postandrewsw, on 21 August 2013 - 12:18 PM, said:

Presumably strRegionList is a string variable?

Use Debug.Print !Region and the same, on a separate line, for !Id. Set a breakpoint by clicking to the left of a statement (in the grey bar); step through the code by pressing F8. Study other debugging techniques.


its going to error message directly from the query , what should i do .give me some idea where i can correct the error
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3320
  • View blog
  • Posts: 11,227
  • Joined: 12-December 12

Re: "Object variable or With block variable not set"

Posted 22 August 2013 - 11:27 AM

I cannot see an error within your posted code. You might post some more code and more information.

Otherwise, you'll need to do some basic debugging. There are numerous things you can do.

strRegionList = strRegionList & ";""" & !Region & """;""" & !Id & """"


  • Comment out this line entirely to see if the recordset can be navigated. If it can, then the error is definitely within this specific line.
  • If you are able to run the code, then you will also be able to step through it (F8).
  • Print-out the .RecordCount, using Debug.Print or a MessageBox.
  • Print-out strRegionList within the loop.
  • Print-out just !Region. If this works, print-out just !Id.
  • If neither work, print-out .Fields(0).Name, etc..


These are essentials skills for any programmer :sorcerer:. That is, not just knowing how to step-through code, but adopting a detailed, and logical, approach to problem-solving.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1