473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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


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
1 1472
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Yang Li Ke | last post by:
Hi guys, Is it possible to know the internet speed of the visitors with php? Thanx -- Yang
4
by: EP | last post by:
On questions of the suitability of Python for CGI, embedded apps, etc., execution speed comes to mind. I previously read some comparisons which did not show Python in a good light in this regard:...
28
by: Maboroshi | last post by:
Hi I am fairly new to programming but not as such that I am a total beginner From what I understand C and C++ are faster languages than Python. Is this because of Pythons ability to operate on...
3
by: linvin333 | last post by:
Hi, Does function overloading affect the speed of execution of the program ? If so what is the reason ? How does it compare with a speed of a program using non-overloded functions ? Linny
4
by: Il Prof | last post by:
Hi to everyone! ;) In C language on Linux, what string access method is faster? 1) Puntatori char str="hello"; char* pstr; pstr = str; // access such as "*pstr"
7
by: YAZ | last post by:
Hello, I have a dll which do some number crunching. Performances (execution speed) are very important in my application. I use VC6 to compile the DLL. A friend of mine told me that in Visual...
12
by: Marty | last post by:
Hi, I am building an application that need high speed of execution. There is a lot of string parsing that I do in VB.NET. Do I gain in speed if all that string parsing is made in a dll coded...
3
by: serge | last post by:
How do I determine which method I should use if I want to optimize the performance of a database. I took Northwind's database to run my example. My query is I want to retrieve the Employees'...
40
by: kavi | last post by:
Hello friends, Could any one tell the way of calculating the speed of c program execution?
1
by: Kelie | last post by:
hello, would there be any speed increase in code execution after python code being compiled into exe file with py2exe? thanks, kelie
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.