Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using form to set defaultvalue property in another form 1

Status
Not open for further replies.

clinresys

Programmer
Jan 28, 2003
10
US
My plan is to expose only certain fields to the end user of an mde for setting default values (no design views allowed)at the form level.

Textboxes in the form to be used to set defaultvalue in the target form have their own defaultvalue set to the defaultvalue of the target form with an expression:

=[Forms]![frmTarget_Form]![misc].[DefaultValue]

that works.

Each of the textboxes in the form used to set defaultvalues has a routine on the afterupdate event:

Private Sub misc_AfterUpdate()
Call StageNDarray("misc", CStr(misc.Value))
End Sub

StageNDarray builds a two dimensional array, the fields and values of the textboxes.

When the button is clicked, the new defaultvalue properties appear in the target form's field property settings exactly right,

(one lines wraps in paste below)

For ndv = 0 To UBound(NewDefaults, 1)
If NewDefaults(ndv, 0) <> &quot;&quot; Then
Forms!sbfFee_Schedule.Controls(NewDefaults(ndv, 0)).DefaultValue = NewDefaults(ndv, 1)
End If
Next ndv

except they don't get saved !!!

It is blowing my mind because they did save the first time the routine worked. Now when I close the target form, it's all undone, with the default values from the first time it worked there to haunt me.

The target form's defaultvalue properties were null for all fields before the first time the routine worked.

Anyone ever try this, or something like it?
Thanks
 
Run time changes do NOT persist. You can open the form to be changed hidden in design mode and then make the changes but if it is open normally they do not save.

Sorry but hope this helps.
 
thanks SBendBuckeye. I recall I did have the target form open in design mode the one and only time the changes persisted.
 
I ended up using a separate table of default values and a dictionary object(like a perl hash)for collecting textbox updates.

If a certain textbox IsNull on SaveRecord, MsgBox asks the user if they want to save as new defaults. If they do, the record currently being used is flagged false, and cloned.

The clone is updated from the dictionary, and the boolean field set to true.

The data entry mode form comes back around via
DoCmd.GoToRecord , , acNewRec
with the new default values displayed.

Using a dictionary overcomes the limitation of not being able to ReDim any other than the last dimension in a multi-dimensional array. (Like where a user might change a control value more than once, and you have a static array of fieldnames and values)

By keeping a table of records of default values for a given form, I can give the end user the choice of undoing (once)the choice to change default values.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top