By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,506 Members | 2,282 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,506 IT Pros & Developers. It's quick & easy.

Setting a variable default value?

P: 21
Would like any suggestions please on how to achieve this - I'm using MS Access 2003.

At present for a simple data entry situation using a form, the user entering the data enters their intials into a field on every record to enable us to identify who made that entry.

Is there a way the user can enter their name just once at the beginning of the session and for it to then be automatically entered in each record they add until the database is next closed?

I suppose it's like setting a variable default field somehow....?
Nov 17 '08 #1
Share this Question
Share on Google+
4 Replies


missinglinq
Expert 2.5K+
P: 3,532
In your form, you can use the AfterUpdate event of the control holding your data to set the DefaultValue for the field. From that time forward, until you either manually change the data or close your form, the data will be entered automatically in each new record. The syntax varies slightly, depending on the datatype of the data. For your use at this time you'd want to use the Text version, but I'll give you all versions for future reference:

For Text fields
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextControlName_AfterUpdate()
  2. If Not IsNull(Me.YourTextControlName.Value) Then
  3.   YourTextControlName.DefaultValue = """" & Me.YourTextControlName.Value & """"
  4. End If
  5. End Sub
For Date fields
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourDateControlName_AfterUpdate()
  2. If Not IsNull(Me.YourDateControlName.Value) Then
  3.   YourDateControlName.DefaultValue ="#" &  Me.YourDateControlName & "#"
  4. End If
  5. End Sub
For Numeric fields
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourNumericControlName_AfterUpdate()
  2. If Not IsNull(Me.YourNumericControlName.Value) Then
  3.   YourNumericControlName.DefaultValue = Me.YourNumericControlName.Value
  4. End If
  5. End Sub
Welcome to Bytes!

Linq ;0)>
Nov 17 '08 #2

P: 21
Many thanks for your reply.
Unfortunately I'm either very thick or very new (or both!)
Could you clarify how you've used the names in your script?
ie: my table name is Asurvivortable
Form name is Asurvivorformshort
The field concerned is locationnow
If you could put it into words of one syllable for me that would be a great help....
Thanks.
Kev
Nov 19 '08 #3

missinglinq
Expert 2.5K+
P: 3,532
Assuming that

LocationNow

is the field you want to "bring forward" and is a text field

Expand|Select|Wrap|Line Numbers
  1. Private Sub LocationNow_AfterUpdate()
  2.   If Not IsNull(Me.LocationNow.Value) Then
  3.     LocationNow.DefaultValue = """" & Me.LocationNow.Value & """"
  4.   End If
  5. End Sub
  6.  
Linq ;0)>
Nov 19 '08 #4

P: 21
Many thanks.
It works brilliantly!
Kev
Nov 20 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.