Auto load fields in form

C

cjfazio

I have a form where users enter multiple records at a time. To save time and
to ensure no mistakes are made, I would like to be able to auto populate some
fields such as the users name, report name, and report number. Is there a
way for users to enter these fields once have them auto populate for each
record they complete.
 
L

Linq Adams via AccessMonster.com

You can do this by using the AfterUpdate event of the field you want to carry
forward. This will automatically carry forward to each ensuing new record
until

You edit the field, after which the new value will be carried forward

You close the form

The exact syntax varies depending on the datatype of the field.

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

Good luck!

Linq
 
C

cjfazio

Ling,

It sounds like what you suggest should meet my needs but I am having a bit
of trouble implementing the event. For a text box I have with a name and
control source called CardNoInitiated1, I tried the following:

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

However the part:

CardNoInitiated1.DefaultValue = """" & Me.CardNoInitiated1.Value &
""""

gave me a compile error of Expected: Expression.

Any thoughts? I am new to VB.
 
C

cjfazio

Linq,

One other question. If I get this script working and I have two people
using the same form but inputting different records what will be the impact
to the populated fields? Will the second person that opened the form see the
populated fields that were entered by the first person?

Chuck
 
C

cjfazio

Linq,

Forget my questions above. When I cut and pasted your code it added a
paragraph mark after the """", thus giving me a syntax error. After I fix
that it worked fine. It's just what I wanted. Thanks.

Chuck
 

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