Access crashes while running startup code..

  • Thread starter every1luvsVB via AccessMonster.com
  • Start date
E

every1luvsVB via AccessMonster.com

Hi people,

I wrote a nice little class method that does a dlookup on form_load of the
start up form. basically if the dlookup returns a value, i assign this to the
caption property of the form..

now i built and tested this and it works fine and i have built onto the app
further since over a number of days / development sessions..

NOW all of a sudden, the app decides to crash on startup, giving me the
'Access is sorry to inconvenience you but has to close -do you want to send
an error report.. etc.'

- held the SHIFT key down and tried again, bypassing the startup code and it
opened without a hitch -i then went ahead and commented out all my form_load
code (for the dlookup..) -tried starting app again without the SHIFT key down
and again, it starts without a problem..

Could any of you learned developers tell me what is wrong with my code?? -the
thing that gets me is that it WAS working and NOTHING was changed to cause it
to suddenly not work..

********************************************************
* Here is my class method:
********************************************************
Public Sub loadEnvironment(thisForm As Form, strSpecificCaption As String)
'This subroutine can be called onLoad of each form to add title, logo, etc...
Dim strClubName, strImagePath, strLogoFileName As Variant

strClubName = DLookup("[txtClubName]", "tblEnvironment")
strImagePath = DLookup("[txtImagePath]", "tblEnvironment")
strLogoFileName = DLookup("[txtLogoFileName]", "tblEnvironment")

'Dynamically load Club Name...
thisForm.Caption = strClubName & " - Membership Application: " &
strSpecificCaption
'If form is not datasheet type; and Logo exists, dynamically load Logo...
If Not (thisForm.DefaultView = 2) Then
If Not IsNull(strLogoFileName) Then
thisForm!imgLogoContainer.Picture = strImagePath &
strLogoFileName
End If
End If

End Sub

********************************************************
* Here is my form_load call:
********************************************************
On Error GoTo Err_Form_Load

Dim varClubName As Variant
Dim mdlUtils As clsUtilities

Set mdlUtils = New clsUtilities
Call mdlUtils.loadEnvironment(Me, "Main Menu")

'If no Club Name value currently exists onLoad of the application,
'then prompt the user to enter one...
varClubName = DLookup("[txtClubName]", "tblEnvironment")

If IsNull(varClubName) Then
Dim WarnMsg As String
Me!tabctlMainMenu.Pages!pgAdmin.SetFocus
WarnMsg = "There is currently no Club Name defined for this
application." & vbCrLf & vbCrLf & "Click the 'Administer Environment' button
to enter a new Club Name..."
MsgBox (WarnMsg)
End If

Exit_Form_Load:
Exit Sub

Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load
********************************************************
Thanks heaps for any advice!
 
J

John Nurick

I'd add some debugging code to create a log file, to make it possible to
discover which line provokes the crash, e.g.

Open "C:\Temp\DebugLog.txt" For Append As #1
Write #1, "Starting " & Now()

Set mdlUtils = New clsUtilities
Write #1 "Set mdlUtils - OK"
Call mdlUtils.loadEnvironment(Me, "Main Menu")
Write #1, "Call mdlUtils.loadEnvironment - OK"

'If no Club Name value currently exists onLoad of the application,
'then prompt the user to enter one...
varClubName = DLookup("[txtClubName]", "tblEnvironment")
Write #1, "Dlookup clubname - OK"

...

After the crash, the last entry in file should show the point reached
before the crash.


Hi people,

I wrote a nice little class method that does a dlookup on form_load of the
start up form. basically if the dlookup returns a value, i assign this to the
caption property of the form..

now i built and tested this and it works fine and i have built onto the app
further since over a number of days / development sessions..

NOW all of a sudden, the app decides to crash on startup, giving me the
'Access is sorry to inconvenience you but has to close -do you want to send
an error report.. etc.'

- held the SHIFT key down and tried again, bypassing the startup code and it
opened without a hitch -i then went ahead and commented out all my form_load
code (for the dlookup..) -tried starting app again without the SHIFT key down
and again, it starts without a problem..

Could any of you learned developers tell me what is wrong with my code?? -the
thing that gets me is that it WAS working and NOTHING was changed to cause it
to suddenly not work..

********************************************************
* Here is my class method:
********************************************************
Public Sub loadEnvironment(thisForm As Form, strSpecificCaption As String)
'This subroutine can be called onLoad of each form to add title, logo, etc...
Dim strClubName, strImagePath, strLogoFileName As Variant

strClubName = DLookup("[txtClubName]", "tblEnvironment")
strImagePath = DLookup("[txtImagePath]", "tblEnvironment")
strLogoFileName = DLookup("[txtLogoFileName]", "tblEnvironment")

'Dynamically load Club Name...
thisForm.Caption = strClubName & " - Membership Application: " &
strSpecificCaption
'If form is not datasheet type; and Logo exists, dynamically load Logo...
If Not (thisForm.DefaultView = 2) Then
If Not IsNull(strLogoFileName) Then
thisForm!imgLogoContainer.Picture = strImagePath &
strLogoFileName
End If
End If

End Sub

********************************************************
* Here is my form_load call:
********************************************************
On Error GoTo Err_Form_Load

Dim varClubName As Variant
Dim mdlUtils As clsUtilities

Set mdlUtils = New clsUtilities
Call mdlUtils.loadEnvironment(Me, "Main Menu")

'If no Club Name value currently exists onLoad of the application,
'then prompt the user to enter one...
varClubName = DLookup("[txtClubName]", "tblEnvironment")

If IsNull(varClubName) Then
Dim WarnMsg As String
Me!tabctlMainMenu.Pages!pgAdmin.SetFocus
WarnMsg = "There is currently no Club Name defined for this
application." & vbCrLf & vbCrLf & "Click the 'Administer Environment' button
to enter a new Club Name..."
MsgBox (WarnMsg)
End If

Exit_Form_Load:
Exit Sub

Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load
********************************************************
Thanks heaps for any advice!
 
E

every1luvsVB via AccessMonster.com

Hi John,

thankyou for the direction forward. This is a great idea to debug which I did
not really think of..

Well after trying your recommendation, I discovered that my code is working
fine and the actual problem was that I changed the project name in the VB IDE
but then neglected to recompile.. Re-compiling solved the problem.

Cheers.
 
J

John Nurick

That's the great thing about systematic debugging. It helps find the
problem as well as the solution!
 
Top