Why is Default Value not working?

  • Thread starter Thread starter Gator
  • Start date Start date
G

Gator

Why when I goto a new record the date is blank?
Here is the code I'm using?

Private Sub PostDate_AfterUpdate()
Me.PostDate.DefaultValue = Chr(34) & Me.PostDate & Chr(34)
End Sub
 
Why not put the default value in table design. Got to Post_Date field in the
table and set the defaultvalue there... Besides you are setting a
defaultvalue in the after update of the field you want to have a default
value?

Maybe you should go for 'new' record...
 
I only want the default to be whatever the previous record's date is,
otherwise it just remains the same. How do I code this in Form Current Event?
 
I mean for New Records, I want the default to be whatever the previous one
is, otherwise nothing happens. I have tried the following code to no avail.

Private Sub PostDate_AfterUpdate()
Me.PostDate.DefaultValue = Me.PostDate
End Sub

Private Sub Form_Current()
If Me.NewRecord Then
Me.PostDate = Me.PostDate.DefaultValue
Else
End If
End Sub
 
Rather than trying to store the date to the control's default value, declare
a module level variable and store the value there.

In the Declarations section of the forms code put something like
Dim dteMyDate as Date

Then in the after update event of your control use:
Private Sub PostDate_AfterUpdate()
dteMyDate = Me.PostDate.Value
End Sub

Then when you navigate to a new record, set the value of the control to your
variable using
Me.PostDate.Value = dteMyDate

HTH,
Chris
 
I'm a novice at coding. Where is the Declaratrions section of the Forms
code? Is that a Load or Current Event?
 
What Chris means is open the module where the afterupdate is located (form in
VBE) At the top of that module you'll find something like Option explicit.
Type under the option explicit the dim statement as Chris mentioned.

hth
 
You don't need a varialbe.
The only problem is you are putting quotes around the value. You don't need
to do that. All you need is

Me.MyTextBox.DefaultValue = Me.MyTextBox
 
The syntax for setting the DefaultValue depends on the datatype of the data:

For Text fields

Private Sub YourTextControlName_AfterUpdate()
If Not IsNull(Me.YourTextControlName.Value) Then
YourTextControlName.DefaultValue = """" & Me.YourTextControlName.Value &
""""
End If
End Sub

For Numeric fields

Private Sub YourNumericControlName_AfterUpdate()
If Not IsNull(Me.YourNumericControlName.Value) Then
YourNumericControlName.DefaultValue = Me.YourNumericControlName.Value
End If
End Sub

For Date fields

Private Sub YourDateControlName_AfterUpdate()
If Not IsNull(Me.YourDateControlName.Value) Then
YourDateControlName.DefaultValue ="#" & Me.YourDateControlName & "#"
End If
End Sub

Once you've set the DefaultValue, you don't have to do ***anything*** else!
You don't have to check for a new record; when a new record is created, the
DefaultValue will automatically be plugged in.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
Back
Top