Next Without For

G

gillettos

Why am I having problems with the following code below.....

Basically I get the "Next witout For" Compile error when running the
code. Understand what its sayin, but by placing the "Next iRange"
outside the If statement kinda defeats the object of what I want to
do....!

Any Ideas????



For iRange = 1 To iRowNo 'set a loop of rows to cyclce down

strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(iRange,
1).Text

For iRange = 1 To iRowNo 'set a loop of rows to cyclce down


If strUsrID = iUsrId Then

Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation

Else

Next iRange 'WONT WORK, ERROR = "Next Without For"

MsgBox "You are not an authorised Administrator of the System",
vbInformation, "Information" 'and display message

End If


--
gillettos
------------------------------------------------------------------------
gillettos's Profile: http://www.thecodecage.com/forumz/member.php?u=2090
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=207715

http://www.thecodecage.com/forumz


--- news://freenews.netfront.net/ - complaints: (e-mail address removed) ---
 
J

Jim Cone

'--
strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(IRange, 1).Text
For IRange = 1 To iRowNo
If strUsrID = iUsrId Then
IsThere = True
Exit For
End If
Next 'IRange

If IsThere Then
Unload FrmNavigation
FrmAdmin.Show
Else
MsgBox "You are not an authorized Administrator of the System", _
vbInformation, "Information"
End If
--
Jim Cone
Portland, Oregon USA
http://tinyurl.com/ExtrasForXL




"gillettos"
<[email protected]>
wrote in message
Why am I having problems with the following code below.....
Basically I get the "Next witout For" Compile error when running the
code. Understand what its sayin, but by placing the "Next iRange"
outside the If statement kinda defeats the object of what I want to
do....!
Any Ideas????

For iRange = 1 To iRowNo 'set a loop of rows to cyclce down
strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(iRange,
1).Text
For iRange = 1 To iRowNo 'set a loop of rows to cyclce down
If strUsrID = iUsrId Then
Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation
Else
Next iRange 'WONT WORK, ERROR = "Next Without For"
MsgBox "You are not an authorised Administrator of the System",
vbInformation, "Information" 'and display message
End If
 
R

Ron Rosenfeld

Why am I having problems with the following code below.....

Basically I get the "Next witout For" Compile error when running the
code. Understand what its sayin, but by placing the "Next iRange"
outside the If statement kinda defeats the object of what I want to
do....!

Any Ideas????


For iRange = 1 To iRowNo 'set a loop of rows to cyclce down

strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(iRange,
1).Text

For iRange = 1 To iRowNo 'set a loop of rows to cyclce down

If strUsrID = iUsrId Then
Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation
End If

If strUsrID <> iUsrId Then
MsgBox "You are not an authorised Administrator of the
System", vbInformation, "Information" 'and display message
End If

Next iRange
 
R

Ron Rosenfeld

For iRange = 1 To iRowNo 'set a loop of rows to cyclce down

strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(iRange,
1).Text

For iRange = 1 To iRowNo 'set a loop of rows to cyclce down

If strUsrID = iUsrId Then
Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation
End If

If strUsrID <> iUsrId Then
MsgBox "You are not an authorised Administrator of the
System", vbInformation, "Information" 'and display message
End If

Next iRange

Just a suggestion if it fits in with what you want to do:

Add an Exit For to the second "If" clause, so you don't cycle through
the msgbox for each row.

......
If strUsrID <> iUsrId Then
MsgBox "You are not an authorised Administrator of the
System", vbInformation, "Information" 'and display message
Exit For
End If
.....
 
S

Simon Lloyd

Why am I having problems with the following code below.....

Basically I get the "Next witout For" Compile error when running the
code. Understand what its sayin, but by placing the "Next iRange"
outside the If statement kinda defeats the object of what I want to
do....!

Any Ideas????



VBA Code:
--------------------
For iRange = 1 To iRowNo 'set a loop of rows to cyclce down

strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(iRange, 1).Text

For iRange = 1 To iRowNo 'set a loop of rows to cyclce down


If strUsrID = iUsrId Then

Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation

Else

Next iRange 'WONT WORK, ERROR = "Next Without For"

MsgBox "You are not an authorised Administrator of the System", vbInformation, "Information" 'and display message

End If

--------------------

You have repeated this line

VBA Code:
--------------------


For iRange = 1 To iRowNo 'set a loop of rows to cyclce down
--------------------


but you only have one NEXT so either delete the line or add a NEXT.


--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?u=1
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=207715

http://www.thecodecage.com/forumz


--- news://freenews.netfront.net/ - complaints: (e-mail address removed) ---
 
G

gillettos

You have repeated this line>

VBA Code:
--------------------For iRange = 1 To iRowNo 'set a loop of rows to cyclce down
--------------------but you only have one NEXT so either delete the line or add a NEXT.



Please ignore that line of code, it should be commented out, I was just
playing in trying to resolve the problem.

I have actually sorted it in a fashion, by moving the msg box after the
next line, it works, only prob being the msgbox comes up everytime, ie,
even with logit users.

I know this is something stupidly obviously but I'm just totally
drained at the mo!!


--
gillettos
------------------------------------------------------------------------
gillettos's Profile: http://www.thecodecage.com/forumz/member.php?u=2090
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=207715

http://www.thecodecage.com/forumz


--- news://freenews.netfront.net/ - complaints: (e-mail address removed) ---
 
S

Simon Lloyd

Please ignore that line of code, it should be commented out, I was just
playing in trying to resolve the problem.

I have actually sorted it in a fashion, by moving the msg box after the
next line, it works, only prob being the msgbox comes up everytime, ie,
even with logit users.

I know this is something stupidly obviously but I'm just totally
drained at the mo!!


This is how it should look:

VBA Code:
--------------------


strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(IRange, 1).Text

For IRange = 1 To iRowNo 'set a loop of rows to cyclce down


If strUsrID = iUsrId Then

Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation

Else

MsgBox "You are not an authorised Administrator of the System", vbInformation, "Information" 'and display message
End If
Next IRange
--------------------


if it does not perform as expected then look at what you are trying to
capture and check you're getting what you expect try this code instead:

VBA Code:
--------------------


strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(IRange, 1).Text
MsgBox strUsrID & " beginning of code"
MsgBox iUsrId & " beginning of code"

For IRange = 1 To iRowNo 'set a loop of rows to cyclce down

If strUsrID = iUsrId Then

Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation

Else
MsgBox strUsrID & " value when if condition failed"
MsgBox iUsrId & " value when if condition failed"
MsgBox "You are not an authorised Administrator of the System", vbInformation, "Information" 'and display message
End If
Next IRange
--------------------


--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?u=1
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=207715

http://www.thecodecage.com/forumz


--- news://freenews.netfront.net/ - complaints: (e-mail address removed) ---
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top