How to Open form as Dialog and then goto new record (1 Viewer)

XelaIrodavlas

Registered User.
Local time
Today, 21:17
Joined
Oct 26, 2012
Messages
174
Hello,

Apologies as I'm sure this will have been asked before but I couldn't find anything on the search.

I want to open a form as dialog to prevent users from going into anything else until they close the new form.

However, I also need to move this form to a new record when it opens.

Code looks like this:
Code:
DoCmd.OpenForm "ApprovalReviews", , , "SupplierID = " & Me!SupplierID, acFormAdd, acDialog 'Dialog to prevent write conflict.
 '####Opening as dialog is preventing the below from running until after the blighter has been closed.... which causes more errors because the form is no longer open.
Forms!ApprovalReviews!sApprovalReviews2.SetFocus
DoCmd.GoToRecord , , acNewRec

Anyone have any suggestions for a workaround?

Thanks All,
A
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:17
Joined
May 7, 2009
Messages
19,229
you add code to ApprovalReviews form's Load Event:

private sub form_load()
DoCmd.GotoRecord,, acNewRec
[sApprovalReviews2].setfocus
end sub
 

JonXL

Active member
Local time
Today, 15:17
Joined
Jul 9, 2021
Messages
153
If you'll only ever use the form to enter data, you can set its DataEntry and AllowAdditions properties to Yes, which you can do through the GUI - no VBA needed.
 

XelaIrodavlas

Registered User.
Local time
Today, 21:17
Joined
Oct 26, 2012
Messages
174
you add code to ApprovalReviews form's Load Event:

private sub form_load()
DoCmd.GotoRecord,, acNewRec
[sApprovalReviews2].setfocus
end sub
I think you may have meant that the other way around(?) but thank you it works!

Code:
Private Sub Form_Load()
Me!sApprovalReviews2.SetFocus
DoCmd.GoToRecord , , acNewRec
End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:17
Joined
Feb 19, 2002
Messages
43,233
If you want to open the form to add new records, open it with --
DoCmd.OpenForm "name", acNormal, , , acFormAdd, acDialog

NO need for code in the form's Load event since that runs no matter how you open the form
NO need to hard code the DataEntry property.
 

Users who are viewing this thread

Top Bottom