How do I programatically change the default value of a field in a table? I will need to prompt the user for the new default value, as well, in order to fully automate the process.
Default Values in Tables
Collapse
X
-
Originally posted by apartainHow do I programatically change the default value of a field in a table? I will need to prompt the user for the new default value, as well, in order to fully automate the process.
The code you would need would be.
Code:Dim strDefaultVal As String strDefaultVal = InputBox "Prompt user for Entry") Me.FieldName.DefaultValue = strDefaultVal Me.Requery
-
Originally posted by mmccarthyCode:Me.FieldName.DefaultValue = strDefaultVal Me.Requery
I thought you'd need to dig into TableDef objects, FieldDef collection, and so on. Cool!
I suppose it's a lot simpler since you're starting from within Access - I tend to look at it from the VB6 viewpoint, where I'm sure I would have to do all that stuff.Comment
-
Originally posted by Killer42Wow! Is that it?!
I thought you'd need to dig into TableDef objects, FieldDef collection, and so on. Cool!
I suppose it's a lot simpler since you're starting from within Access - I tend to look at it from the VB6 viewpoint, where I'm sure I would have to do all that stuff.
Someday, you know 'when you have time and nothing else to do' you should check out the msdn references to Access VBA libraries.
Mary
Comment
-
I know this sounds like a really dumb question, but I am very new at VBA in Access. Where do I put the code you just gave me?
If you think this is dangerous, is there another way to do it so when the sales tax changes, it won't change all of the records up to the point of the change?Comment
-
Originally posted by apartainI know this sounds like a really dumb question, but I am very new at VBA in Access. Where do I put the code you just gave me?
If you think this is dangerous, is there another way to do it so when the sales tax changes, it won't change all of the records up to the point of the change?
Create this form with a textbox to put the new sales tax in and a command button to apply it. When you have this done and the form is opening based on clicking the button on the main form. Let me know.
Give me the new form name.
The name of the textbox
The name of the command button
and
The name of the control on the main form that is set to the field for the sales tax.
MaryComment
-
OK, done.
New popup form name: ChangeSTForm
Text Box: NewRate
Command Button: Command3
Control on main form set to field for sales tax: Form3.[Sales Tax]
Originally posted by mmccarthyThe best way to handle making this kind of change is to give the user a popup form opened on a command button click to change the sales tax rate.
Create this form with a textbox to put the new sales tax in and a command button to apply it. When you have this done and the form is opening based on clicking the button on the main form. Let me know.
Give me the new form name.
The name of the textbox
The name of the command button
and
The name of the control on the main form that is set to the field for the sales tax.
MaryComment
-
Originally posted by apartainOK, done.
New popup form name: ChangeSTForm
Text Box: NewRate
Command Button: Command3
Control on main form set to field for sales tax: Form3.[Sales Tax]
Code:Private Sub Command3_Click() If NOT IsNull(Me.NewRate) Then Forms![Form3]![Sales Tax].DefaultValue = "=" & Me.NewRate Else Msgbox "You haven't entered a new sales tax figure" Me.NewRate.SetFocus End Sub End If Forms("Form3").Refresh DoCmd.Close End Sub
Comment
-
I think that this concerns only the field property in a form, but not the table!
For the table properties... The tableDefrs are waiting for you ;)
:)
Originally posted by Killer42Wow! Is that it?!
I thought you'd need to dig into TableDef objects, FieldDef collection, and so on. Cool!
I suppose it's a lot simpler since you're starting from within Access - I tend to look at it from the VB6 viewpoint, where I'm sure I would have to do all that stuff.Comment
Comment