"Set field" prob (1 Viewer)

cos

Registered User.
Local time
Today, 10:54
Joined
Jul 13, 2012
Messages
81
hi guys,

basicly, i got an Add Contact button, which runs the macro attached to this post, what opens a blank form; at which stage i wish for the form to enter a value in one of the fields from another form:

On Load event:
Code:
Private Sub Form_Load()
Me.ShopInfoID = [Forms]![zx_Shop]![ShopInfoID_TBL_ShopInfo]

End Sub

when the form is opened in form view, from the click on the Add button on a previous form, the form is opens completely blank with the specifiedID to this form (ContactID) to "New", with the ShopInfoID field blank..

what am i doing wrong? is there some other way of doing this or is access being an idiot yet again?

please see if you can help :)
 

Attachments

  • addButtonMacro.jpg
    addButtonMacro.jpg
    43.4 KB · Views: 51
Last edited:

stopher

AWF VIP
Local time
Today, 10:54
Joined
Feb 1, 2006
Messages
2,395
When a value is entered in ShopInfoID_TBL_ShopInfo, does the user exit from the control? If not, then it's possible that the value has not yet been stored in the control.

Another possibility... is 01_ContactAdd already open? If it is then the OnLoad event won't fire.

hth
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:54
Joined
Feb 19, 2002
Messages
43,478
I use the Where argument of the OpenForm Method/Action to pass a record ID to the form I am opening. This makes the form open to the specified record or if it is not found, the form opens in Add mode. This is more flexible than only opening to a "new" record.

The line of code to populate ShopInfoID does NOT belong in the Load event. The best event to use is the BeforeInsert event. The BeforeInsert event runs as soon as someone types something in any control. The benefit of using this event is that your code won't dirty the record. The record won't get dirtied until the user types something and he will "know" that he did something. If you use some other event to force a value into a control, the user doesn't know that simply opening the form dirtied it. This leaves him confused if he gets messages prompting him to save or it can result in blank records being created when the user opens the form but doesn't actually enter any data. Additionally, since the code is in the BeforeInsert event it will not affect existing records.
 

Users who are viewing this thread

Top Bottom