Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Object variable or With block variable not set error?

  Asked By: Juana    Date: Dec 07    Category: MS Office    Views: 1074
  

I have a simple form with a two option buttons op1 and op2. Selecting
op1 should execute the following lines of code however, I am getting an
error Object variable or With block variable not set error.
Do I need to declare any other variab;e/ form to avoid this.?

Private Sub CommandButton1_Click()
Dim plate As Boolean
Load frm
frm.Show
plate = frm.op1.Value

If plate = True Then
LookAhead = 110
Else
LookAhead = 93
End If
End Sub

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Vicki Fields     Answered On: Dec 07

Specifically which line of the code  is throwing the error?

 
Answer #2    Answered By: Isra Demir     Answered On: Dec 07

it could be the line

plate = frm.op1.Value

what type is plate?

perhaps your code  should be:

Set plate = frm.op1.Value

not sure if this is the problem...

 
Answer #3    Answered By: Abrianna Rossi     Answered On: Dec 07

It is "plate = frm.op1.Value" Seems like it is not able to assign the
value from the option  box to the boolean variable  plate.

 
Answer #4    Answered By: Damon Jones     Answered On: Dec 07

: I have a simple  form with a two option  buttons op1 and op2.
: Selecting op1 should execute  the following lines  of code

No. Clicking on the CommandButton1 button should execute
your lines of code. To execute these lines on a change of op1
you would need this.

Private Sub op1_Change()
Dim plate As Boolean
Load Frm
Frm.Show
plate = Frm.op1.Value

If plate = True Then
LookAhead = 110
Else
LookAhead = 93
End If
End Sub

Or perhaps:

Private Sub op1_Click()
Dim plate As Boolean
Load Frm
Frm.Show
plate = Frm.op1.Value

If plate = True Then
LookAhead = 110
Else
LookAhead = 93
End If
End Sub

Neither one of these makes sense because Frm is already
loaded and shown (otherwise op1 could not be clicked).


: however, I am getting an error  Object variable  or With block
: variable not set  error.

You should be getting a "form already shown..." error.
Perhaps you are not showing us enough code.

 
Answer #5    Answered By: Varun Mehta     Answered On: Dec 07

It sounds as though either frm or op1 does not exist. However, to have got
this far, frm presumably does exist, so that leaves op1 as suspect.

Do you have Option Explicit set  and have you done a compile? It will pick
up most instances of missing items.

When it fails, you will be able to look at frm and op1 in the debugger and
see that they exist.

Check that it is called op1 and that it is indeed in form  frm.

 
Didn't find what you were looking for? Find more on Object variable or With block variable not set error? Or get search suggestion and latest updates.




Tagged: