Return without GoSub

stevenblanc

Registered User.
Local time
Yesterday, 19:12
Joined
Jun 27, 2011
Messages
103
Greetings folks,

So I spent the last couple days dug deep into my database project and it was all coming along smoothly until I had an untimely system crash. Fortunately I save regularly so I only lost about 5 minutes of work.

Unfortunately, I do not backup regularly otherwise I'm sure I could just avoid this entirely.

I have a form, frmInterface_Actions; which upon resizing runs the following code:

Private Sub Form_Resize()
Dim intSpacer, intRight As Integer
Dim ctl As Control
intSpacer = 420
intRight = 368

For Each ctl In Me.Controls

If (InStr(UCase(ctl.Name), UCase("nav"))) = 0 Then ctl.Width = (Form.InsideWidth - (intSpacer * 2.5)) / 2

If (InStr(UCase(ctl.Name), UCase("cat3"))) > 0 Or (InStr(UCase(ctl.Name), UCase("cat4"))) > 0 Then
If (InStr(UCase(ctl.Name), UCase("nav"))) = 0 Then
'Right Side Controls
ctl.Left = (intSpacer * 1.5) + ctl.Width
Else
ctl.Left = (Form.InsideWidth) - (intSpacer) - intRight
End If
Else
If (InStr(UCase(ctl.Name), UCase("nav"))) = 0 Then
'Left Side Controls
ctl.Left = intSpacer
Else
ctl.Left = (Form.InsideWidth / 2) - (intSpacer / 4) - intRight
End If
End If

Next ctl

End Sub

After my crash however I get the following error:

The expression On Resize you entered as the event property setting produced the following error: Return without GoSub.

Now, I can temporarily remedy this problem simply by opening the form, going into properties and clicking the view code (...) button for the On Resize event. After that, problem disappears until the next time I restart Access.

Is there a way to solve this problem permanently without rebuilding the form?

Cheers,


Steven
 
The problem is likely the use of single line IF's and multi-line IF's in the same procedure. Change them to multi-line IF's.
 
The problem is likely the use of single line IF's and multi-line IF's in the same procedure. Change them to multi-line IF's.
Bob,
I've never known that to be an issue. I take it you have?
 
@Steven:
You do know the following line:
Dim intSpacer, intRight As Integer
...will Dim intSpacer as a Variant and not an Integer, right?
 
Thanks Bob. I will try it this evening when I have time to work on my database.

@RuralGuy: I always thought that a series of items would all take the type specified, ie:

dim strOne, strTwo, strThree as string
 
You can also remove all the UCase functions because they are not adding any value. "nav" is the same as "NAV" as far as VBA is concerned.

Maybe you could try a decompile. Make sure you're fully backed up.

Have you made any changes to your code between when it was working and when it wasn't?

Chris
 
Unbelievable. I changed the single line if to a block if and presto! No more problem.

I'll keep that in mind for the future!
 
Unbelievable. I changed the single line if to a block if and presto! No more problem.
yeahsmile.jpg
 
That is interesting about the mixed Ifs. I have always used mixed Ifs and never ever had a problem so no way I would have guessed that. Another of those excellent pieces of information one gets by reading this forum. Knowing to try that could save many hours of anguish.

I also noticed the code refers to Form.InsideWidth
This is not a properly specified property. Every object or property in VBA should be specified by including Me (or the full name starting with the collection eg Forms.)

Otherwise Access guesses and you really don't want that. Although the obvious choice of the current class object is usual, I have seen Access get confused if the Me is not included where multiple forms are open and have controls with the same name.

I would also suggest reading the InsideWidth once into a variable and using that variable in the rest of the code. It makes for more readable code and I also expect it would be faster to refer to a variable than repeatedly refer to a property of an object.
 
Lots of good suggestions in this thread. Thanks everyone.
 

Users who are viewing this thread

Back
Top Bottom