Static variable declaration breaks editor

grinnZ

Registered User.
Local time
Today, 03:59
Joined
Jun 29, 2011
Messages
38
Code:
Option Compare Database
Option Explicit

'These are used as rollbacks
'Called by cmdCancel_click()
'Updated by Form_Current
Static RBBidPrice As Single
Static RBBuyoutPrice As Single
Static RBDeposit As Single
Static RBAHCut As Single
I am experiencing strange editor behavior with and without the static variable declarations. Without them all is well. Yet once declared the dropdown menu that appears after a period is typed (e.g. Me.) no longer works.

Does anyone have any thoughts on this? Is there a setting that I have missed? Or should I simply stay away from static variables? :confused:

Additional Information...
When added and trying to open the form I am notified by the program with this dialog...

The expression On Load you entered as the event property setting produced the following error: Invalid outside procedure.

I also receive the same message pointing to the On Current expression with the same invalid outside procedure error.

Code:
Private Sub Form_Load()

    Dim db As Database
    Dim rst As DAO.Recordset
    
    Set db = CurrentDb
    Set rst = CurrentDb.OpenRecordset("qryMarkSold")
    
    With rst
        Me.RecordSource = "qryMarkSold"
        .MoveFirst
        Me.Bookmark = .Bookmark
        .Close
    End With
    
    Set rst = Nothing
    Set db = Nothing
    
End Sub


Private Sub Form_Current()

    With Me
        .cboComposition.RowSource = CompositionComboSQL(.cboType)
        
        'Set rollbacks
        RBBid = .txtBid_Price
        RBBuyout = .txtBO_Price
        RBDeposit = .txtDeposit
        If Not IsNull(.txtAH_Cut) Then
            RBAHCut = .txtAH_Cut
        
        End If
    End With
    
End Sub
 
Last edited:
I don't think you can declare a STATIC outside a sub. Besides, would it make sense? There is no way the thing can keep its value from one run of Access to the next.
 
spkiepl is exactly right, and the error message is telling you exactly that. Invalid outside procedure. If you need to retain the values during the run declare them as public instead of static, or move them inside a sub or function and declare them as static.
 
Thank you gentlemen. Your inputs have helped and are most appreciated.
 

Users who are viewing this thread

Back
Top Bottom