Solved Way to avoid form flashing when load full records and goto newrecord? (1 Viewer)

Babycat

Member
Local time
Today, 13:41
Joined
Mar 31, 2020
Messages
275
Hi Everyone

My table TBLPRODUCT have a number of records.
I want to addnew record but it requires to open form FrmProduct with full records from table.
So I tried with code:
Code:
DoCmd.OpenForm "FrmProduct"
DoCmd.GoToRecord acDataForm, "FrmProduct", acNewRec

You can imagine it requires two steps: Open and display first record, then go to new record. This makes form flashing.

I dont want to use
Code:
DoCmd.OpenForm "FrmProduct", , , , acFormAdd
becasue it does not load other existing records into form.

I have tried DoCmd.Echo false (then true) but it did not work.

May anyone help to advise a solution?

Thank you!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:41
Joined
May 7, 2009
Messages
19,233
you can remove the second code, when you use the Form's
Load event to GoTo newrecord.
 

Babycat

Member
Local time
Today, 13:41
Joined
Mar 31, 2020
Messages
275
you can remove the second code, when you use the Form's
Load event to GoTo newrecord.
Thank Arnelgp

I also have other button to open the form FrmProduct not in newrecord mode.
Thus, how to differentiate them? Should I make a global varibale so that Load event can perform according.
My bad habit is always try to minimize number of global variable unless it must...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:41
Joined
May 7, 2009
Messages
19,233
you can pass an OpenArgs when you open your form:

DoCmd.OpenForm FormName:="yourForm", OpenArgs:="New"

now on the Load Event of "yourForm"

Private Sub Form_Load()
If Me.OpenArgs & "" = "New" Then
DoCmd.GoToRecord,,acNewRec
End If
 

Babycat

Member
Local time
Today, 13:41
Joined
Mar 31, 2020
Messages
275
you can pass an OpenArgs when you open your form:

DoCmd.OpenForm FormName:="yourForm", OpenArgs:="New"

now on the Load Event of "yourForm"

Private Sub Form_Load()
If Me.OpenArgs & "" = "New" Then
DoCmd.GoToRecord,,acNewRec
End If
Oh, now I understand about OpenArgs, I have never known and used it.
A great learning for today.

Much appreciated your helps.
 

Users who are viewing this thread

Top Bottom