'Object variable or With block variable not set'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandy21380
    New Member
    • Mar 2007
    • 7

    'Object variable or With block variable not set'

    I keep getting the error 'Object variable or With block variable not set' with the following code. 'i' is integer, ViewOptions is OptionBox.

    Any idea what I'm doing wrong?

    Code:
    For i = 0 To 4
        If ViewOptions.Value = 1 Then
             If i = 0 Then
                If IsNumeric(strCriteria(i)) Then
                    LinkCriteriaFinal = "(" & LinkCriteria(i) & " like " & strCriteria(i) & " &'*' )"
                Else
                    LinkCriteriaFinal = "(" & LinkCriteria(i) & " like '" & strCriteria(i) & "' &'*' )"
                End If
            Else
                If IsNumeric(strCriteria(i)) Then
                    LinkCriteriaFinal = LinkCriteriaFinal & " and (" & LinkCriteria(i) & " like  " & strCriteria(i) & " & '*' )"
                Else
                    LinkCriteriaFinal = LinkCriteriaFinal & " and (" & LinkCriteria(i) & " like  '" & strCriteria(i) & "' & '*' )"
                End If
            End If
        Else
            If i = 0 Then
                If IsNumeric(strCriteria(i)) Then
                    LinkCriteriaFinal = "(" & LinkCriteria(i) & " like " & strCriteria(i) & " &'*' )"
                Else
                    LinkCriteriaFinal = "(" & LinkCriteria(i) & " like '" & strCriteria(i) & "' &'*' )"
                End If
            Else
                If IsNumeric(strCriteria(i)) Then
                    LinkCriteriaFinal = LinkCriteriaFinal & " or (" & LinkCriteria(i) & " like  " & strCriteria(i) & " & '*' )"
                Else
                    LinkCriteriaFinal = LinkCriteriaFinal & " or (" & LinkCriteria(i) & " like  '" & strCriteria(i) & "' & '*' )"
                End If
            End If
         End If
    Next i
    Last edited by Killer42; Mar 5 '07, 08:29 PM. Reason: Please put [CODE]...[/CODE] tags around your code
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Where in this code is the error happening?

    If it's pointing to ViewOptions.Val ue then we probably need to know more about what ViewOptions is, and how it's defined. Also, what version of VB is this?

    Comment

    • sandy21380
      New Member
      • Mar 2007
      • 7

      #3
      I'm not sure where the error is occurring, how can I tell?

      Comment

      • sandy21380
        New Member
        • Mar 2007
        • 7

        #4
        I'm using Access 97. ViewOptions is an Option Box with two radio buttons, one with value of 1 and the other with value of 2. I have it defined as follows: Dim ViewOptions As OptionGroup

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by sandy21380
          I'm not sure where the error is occurring, how can I tell?
          Doesn't Access stop and point to the line of code when it reports the error?

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by sandy21380
            I'm using Access 97. ViewOptions is an Option Box with two radio buttons, one with value of 1 and the other with value of 2. I have it defined as follows: Dim ViewOptions As OptionGroup
            I'm having a little trouble getting this straight in my mind. Do you have an option group on the form which you created through the GUI, or one which you created in code with the Dim statement, or both?

            I suspect that the answer to this will provide the answer to your problem.
            Last edited by Killer42; Mar 6 '07, 08:06 AM. Reason: Typo

            Comment

            • vijaydiwakar
              Contributor
              • Feb 2007
              • 579

              #7
              Dear the error 'Object variable or With block variable not set' is occured where ur using an object without allocating memory for it. so i've seen one line that is always use new keyword to allocate the memory for any object or use set keyword to do so
              try it

              Comment

              • sandy21380
                New Member
                • Mar 2007
                • 7

                #8
                Originally posted by Killer42
                I'm having a little trouble getting this straight in my mind. Do you have an option group on the form which you created through the GUI, or one which you created in code with the Dim statement, or both?

                I suspect that the answer to this will provide the answer to your problem.

                I deleted the Dim statement and it works just fine!

                Thank you so much!

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Originally posted by sandy21380
                  I deleted the Dim statement and it works just fine!
                  Thank you so much!
                  Glad we could help. :)

                  Comment

                  Working...