Sloooow CODE

D

DS

I'm running this code, but its a little slow. Am I doing something
wrong? Is there abetter way to do this?

Private Sub Command67_Click()
DoCmd.OpenForm "Buttons", acNormal, "", "", acHidden
Forms!Buttons!Expr1.Visible = False
Forms!Buttons!Expr2.Visible = False
Forms!Buttons!Expr44.Visible = True
DoCmd.GoToRecord acForm, "Buttons", acNewRec
Forms!Buttons!CustomerNum = 1
Forms!Buttons!SalesServer = Forms!Patrons!SS
Forms!Buttons!TableNumber = Forms!Patrons!TM
Forms!Buttons!Guests = Forms!Patrons!Pat
Forms!Buttons!BText140 = Forms!Patrons!LocationPatrons
Forms!Buttons!SalesTax = Forms!Patrons!PTax
Forms!Buttons!BSCheckType = Forms!Patrons!PCType
Forms!Buttons!TInUse = True
DoCmd.Close acForm, "Patrons"
DoCmd.OpenForm "Menus", acNormal, , , , acHidden
If Forms!Menus!ListMenu.ListCount = 1 Then
Forms!Menus!ListMenu.Selected(0) = True
ElseIf Forms!Menus!ListMenu.ListCount = 0 Then
DoCmd.Close acForm, "Menus"
DoCmd.OpenForm "NoMenus"
ElseIf Forms!Menus!ListMenu.ListCount > 1 Then
Forms!Menus.Visible = True
End If
Forms!Buttons.Visible = True
DoCmd.RunCommand acCmdSaveRecord
Forms!Buttons!List215.Visible = False
End Sub

Thanks
DS
 
A

Albert D.Kallal

You can correct me, but looks like you are opening up a form, adding a new
record, and then setting some values.
And then hiding the form.

If a user is going to do this, then what you have makes sense. However, you
really as a rule don't want to use code to *launch* a form, then use code to
modify values in the form, and then hide it.

Forms are quite costly in terms of display, load, and execution time.

You would be much better to use sql, or even a reocrdset to add that new
record, and likely you would find things about 100, or more times faster.

That means 100 seconds would become one second....

here what some code would look like to add a new record:

dim rstRecords as dao.RecordSet

set rstRecords = currentdb.OpenReocrdSet("tblPatrons")

rstReocrds.AddNew

rstRecords!CustomerNum = 1
rstRecords!SalesServer = Forms!Patrons!SS
rstRecords!TableNumber = Forms!Patrons!TM
rstRecords!Guests = Forms!Patrons!Pat
rstRecords!BText140 = Forms!Patrons!LocationPatrons
rstRecords!SalesTax = Forms!Patrons!PTax
rstRecords!BSCheckType = Forms!Patrons!PCType
rstRecords!TInUse = True



rstRecords.Update

rstReocrds.Close



If you look at the above, we added a record to table "tblPatrons", and then
used code. This means we DO NOT have to open up a form, the form does not
have to be loaded. We don't have to play with visible settings etc.



So, the lesson in the above code example is that to update data in a table,
and especially to add a "NEW" record to a table, then we can use code. I
would only use a form if in fact the user actaully needs to edit the data.



So, if the user does NOT need to see the data, then we as a general rule
will use code, and not a form. It is much faster, and learning this concpet
also opens up the world of dataprocessing, and routines that can udate large
amounts of data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ByPass key ms access 2016 0
Nested IF Problem 1
Cant See Form 2
Proper Code? 2
subform works every other time 1
Find Record Question 2
Popup form 3
Assistance with Subform Synching 9

Top