PDA

View Full Version : Solved: GoTo in VBA



Ethan
05-02-2012, 12:13 PM
Hello all,

I try the following but it does not work. [error = "object required"]
Can anyone tell me why?


If CheckBox1 = True And TextBox2.Value < texbox7.Value Then GoTo Option1

If CheckBox1 = True And TextBox2.Value > TextBox7.Value And TextBox2.Value < TextBox7.Value + TextBox8.Value Then GoTo Option2

If CheckBox1 = True And TextBox2.Value > TextBox7.Value + mytot3 + mytot2 Then GoTo Option3

Option1:
MsgBox ("Verlof")

Option2:
MsgBox ("Verlof & BW")

Option3:
MsgBox ("Verlof & BW & TVT")

Bob Phillips
05-02-2012, 12:15 PM
If CheckBox1 = True And TextBox2.Value < texbox7.Value Then Goto Option1

If CheckBox1 = True And TextBox2.Value > TextBox7.Value And _
TextBox2.Value < (Val(TextBox7.Value) + Val(TextBox8.Value)) Then Goto Option2

If CheckBox1 = True And TextBox2.Value > (Val(TextBox7.Value) + mytot3 + mytot2) Then Goto Option3

Option1:
MsgBox ("Verlof")

Option2:
MsgBox ("Verlof & BW")

Option3:
MsgBox ("Verlof & BW & TVT")

Ethan
05-02-2012, 12:18 PM
I am sorry, the error persists

Tinbendr
05-02-2012, 12:36 PM
[error = "object required"]
Can anyone tell me why?


If CheckBox1 = True And TextBox2.Value < texbox7.Value Then GoTo Option1
Typo
If CheckBox1 = True And TextBox2.Value < TextBox7.Value Then GoTo Option1

Ethan
05-02-2012, 01:00 PM
:banghead: what a fool I am
Thanks guys.

Aussiebear
05-03-2012, 01:42 AM
Try using Option Explicit at the top of your code, as it will pick up these sorts of issues

snb
05-03-2012, 02:19 AM
or


If CheckBox1 Then
if TextBox2.Value < TextBox7.Value Then
c01=""
ElseIf TextBox2.Value > TextBox7.Value And TextBox2.Value < TextBox7.Value + TextBox8.Value Then
c01= " & "BW"
ElseIf TextBox2.Value > TextBox7.Value + mytot3 + mytot2 Then
c01=" & BW & TVT"
End If
End If

MsgBox "Verlof" & c01

Ethan
05-03-2012, 02:55 AM
Thanks SNB!