By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,323 Members | 1,963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,323 IT Pros & Developers. It's quick & easy.

Is there a way to speed up execution of this code?

P: n/a

Hi there.

I have the following code in the open event of a form. Most of it sets
or checks the value of certain variables so that the form opens
properly. It also sets the recordsource for the form. It all works
correctly. However, It runs very slowly and it takes a couple of seconds
for the form to open. Is there anything I can do to speed it up that
won't change the functionality? Or do I have to find otherways of
accomplishing what this form does?

--Code Start--

Private Sub Form_Open(Cancel As Integer)

streditmode = ""
If Not IsNull(Me.OpenArgs) Then
streditmode = Me.OpenArgs
DoCmd.Maximize

Else
DoCmd.CancelEvent 'Cancel opening of the form and give the user an
error message
FormattedMsgBox "Error - Open Mode not passed to form. This form
must be opened through code.@ If you opened this form from the database
window, please don't do this. Otherwise, Please report this error to the
Program Administrator@", vbCritical, "Error"
End If

If cbxSelectContact.Visible Then
cbxSelectContact.SetFocus
If (streditmode = "E" Or streditmode = "B") And Not Me.FilterOn Then
FormattedMsgBox ("Please select a contact before you do anything
else."), vbInformation + vbOKOnly, "Selection Required"
btnViewBusinessCard.Caption = "View Business Card"

Else
btnViewBusinessCard.Caption = "Add Business Card"
CbxSalutation.SetFocus
End If

If UCase(streditmode) = "B" Then 'Browse mode, so lock the appropriate
controls!

If Not LockControlsForBrowse(Me) Then
DoCmd.CancelEvent 'Don't continue to open the form!
FormattedMsgBox "An error occured while setting up this form
for Browse Mode. @Please report this error to the Program
Administrator@", vbCritical, "Error"
End If
End If

If streditmode = "A" Then
Form.Caption = "Contacts - Add Mode"
cbxSelectContact.Visible = False
Box94.Visible = False
cmdImportContacts.Visible = True
cmdImportContacts.Left = 0.079
ElseIf streditmode = "E" Or streditmode = "B" Then
If streditmode = "E" Then
Form.Caption = "Contacts - Edit Mode"
Else
If streditmode = "B" Then
Form.Caption = "Contacts - Browse Mode"
End If
End If
cmdImportContacts.Visible = False
cbxSelectContact.Visible = True
Box94.Visible = True
btnViewBusinessCard.Visible = True
End If
End If
End Sub

--Code End--

One of the things I was thinking was I could use Select Case instead of
if-then statements for setting all the streditmode arguments. Would this
speed up the form?

Thank you

Colin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I can't see anything in the code you posted that I would expect to cause a
noticeable delay. Perhaps the code in the 'LockControlsForBrowse' function
may be the problem?

Are you certain that it is the code that is the problem at all? What if you
comment out all of the code in the Open event - how long does the form take
to open then?

--
Brendan Reynolds

"ColinWard" <je*********@hotmail.com> wrote in message
news:40*********************@news.frii.net...

Hi there.

I have the following code in the open event of a form. Most of it sets
or checks the value of certain variables so that the form opens
properly. It also sets the recordsource for the form. It all works
correctly. However, It runs very slowly and it takes a couple of seconds
for the form to open. Is there anything I can do to speed it up that
won't change the functionality? Or do I have to find otherways of
accomplishing what this form does?

--Code Start--

Private Sub Form_Open(Cancel As Integer)

streditmode = ""
If Not IsNull(Me.OpenArgs) Then
streditmode = Me.OpenArgs
DoCmd.Maximize

Else
DoCmd.CancelEvent 'Cancel opening of the form and give the user an
error message
FormattedMsgBox "Error - Open Mode not passed to form. This form
must be opened through code.@ If you opened this form from the database
window, please don't do this. Otherwise, Please report this error to the
Program Administrator@", vbCritical, "Error"
End If

If cbxSelectContact.Visible Then
cbxSelectContact.SetFocus
If (streditmode = "E" Or streditmode = "B") And Not Me.FilterOn Then
FormattedMsgBox ("Please select a contact before you do anything
else."), vbInformation + vbOKOnly, "Selection Required"
btnViewBusinessCard.Caption = "View Business Card"

Else
btnViewBusinessCard.Caption = "Add Business Card"
CbxSalutation.SetFocus
End If

If UCase(streditmode) = "B" Then 'Browse mode, so lock the appropriate
controls!

If Not LockControlsForBrowse(Me) Then
DoCmd.CancelEvent 'Don't continue to open the form!
FormattedMsgBox "An error occured while setting up this form
for Browse Mode. @Please report this error to the Program
Administrator@", vbCritical, "Error"
End If
End If

If streditmode = "A" Then
Form.Caption = "Contacts - Add Mode"
cbxSelectContact.Visible = False
Box94.Visible = False
cmdImportContacts.Visible = True
cmdImportContacts.Left = 0.079
ElseIf streditmode = "E" Or streditmode = "B" Then
If streditmode = "E" Then
Form.Caption = "Contacts - Edit Mode"
Else
If streditmode = "B" Then
Form.Caption = "Contacts - Browse Mode"
End If
End If
cmdImportContacts.Visible = False
cbxSelectContact.Visible = True
Box94.Visible = True
btnViewBusinessCard.Visible = True
End If
End If
End Sub

--Code End--

One of the things I was thinking was I could use Select Case instead of
if-then statements for setting all the streditmode arguments. Would this
speed up the form?

Thank you

Colin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.