Default Value Question

  • Thread starter Thread starter Vinnie
  • Start date Start date
V

Vinnie

Re-Post, origanlly posted on access.forms

Hello all,

Is there a way (module or something), that will Set the Default Value of a
Certian Field to a Value I assign to it?

Specifics:
50 Forms in Database.
All Forms Have a Field [SeatNumber]. I would llike all the Forms to be
Static i.e: SeatNumber=5 (for all 50 Forms). Right now, I have to Open the
Control Properties for All 50 Forms to set the Default Value.

I cant set the Default Value in the Table itself, because it is linked and
there are 42 other database doing the same thing.

Any help would be appreciated as usual !

Vincent
 
Vincent,

Oh, this one was fun... (cuz I'm slow and still learning... but I *did*
find the F1 key!!!)

I stole some of Allen Browne's code posted in the NG and modified it to
suit (I was missing that essential form variable definition....)

Put this in a separate module (not in a form module), and run, e.g.
Public Sub GlobalChangeControlDefault(ByVal strControlName As String,
ByVal intDefault As Integer)
'---I nicked most of this code from one of Allen Browne's posts...
thanks Allen!
'---Sample run:
' GlobalChangeControlDefault "SeatNumber", 50

Dim accObj As AccessObject
Dim frm As Form
Dim ctl As Control
Dim strDoc As String

For Each accObj In CurrentProject.AllForms
strDoc = accObj.Name
DoCmd.OpenForm strDoc, acDesign, WindowMode:=acHidden
Set ctl = Forms(strDoc).Controls(strControlName)
ctl.DefaultValue = intDefault
DoCmd.Close acForm, strDoc, acSaveYes
Next

Set ctl = Nothing
Set frm = Nothing
Set accObj = Nothing
End Sub
 
Thanks for the response !
WAY OVER MY HEAD ! ! !
LoL
I get the part on how to create a new module and paste that code in there.
but how do I "Run" it?

Vincent
 
Back
Top