Setting form Field Default values with code

G

Guest

I have a form with 4 fields that need filled on a new record. Typically 50,
or so, new records will be added at a time. 3 of the 4 fields will have the
same value in each record. I have a dailog form with Option Group that gets
me to adding records. My idea was to type the values in on the dialog form
and use those values to update form field Default Values. I've had varying
success, but never got all 3 values set; or I had error msgs in the fields of
a new record. Can this be done with code? Thanks
 
D

Duane Hookom

You can use code to set default values of controls on forms. If you have
code or error messages that you would like to share, someone might be able
to assist.
 
G

Guest

I get #NAME? showing in the fields with the form in normal view, but in
design view they appear to be set correctly w/ the code below.



Private Sub def2_AfterUpdate()

Dim stWhereCriteria As String
Dim stFrmName As String
Dim stDefValue2 As String

stFrmName = "subfTable2"
stDefValue2 = Me!def2

Select Case Me!def2

Case Is = Null

Case Else
DoCmd.openform stFrmName, acDesign, , stWhereCriteria
Form_subfTable2.ff2.DefaultValue = stDefValue2
DoCmd.Save
DoCmd.Close
'DoCmd.GoToControl continue

End Select


End Sub
 
D

Duane Hookom

You need to include quotes when setting a default value. Try this:

Form_subfTable2.ff2.DefaultValue = """" & stDefValue2 & """"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top