AutoFill Form Field

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

Gator

How do I get a field to autofill the same value as the previous record when I
goto a new record. The field's control source is the table field. Can I use
autofill in Default value?
 
Hi,
Private Sub controlname_AfterUpdate()
Me.controlname.DefaultValue = Chr(34) & Me.controlname & Chr(34)
End Sub

Thus if the user enters XYZ it will set the DefaultValue property to
"XYZ"
which will be used for the next entry.

Jeanette Cunningham
 
The Date is the first control for a new record. When I go to a new record
the date is blank. Should I use some code to check if the control is blank
then add the date from the previous record? I have a calendar control at my
option to use to enter a date. I think I need code that Auto fills the date
when there is a new record. Can you help me with that code?
 
Gator,

Open your form in design view then open you VBA window. Directly underneath
Option Compare Database, place this code:
Private ctrl1 As String 'CustLast
Private ctrl2 As String 'OfficeNo
Private ctrl3 As String 'Officer
Private ctrl4 As String 'Region
Private ctrl5 As String 'Closer

Use as many as you need and if you need less than 5 then just delete the
rest. The name I gave them are my field names and are reference so I know
which control is what. So far so good right?

In the On Click event of your command button, place this code:
ctrl1 = CustLast
ctrl2 = OfficeNo
ctrl3 = Officer
ctrl4 = Region
ctrl5 = Closer
DoCmd.GoToRecord acForm, "frmclosingandfundinginfo", acNewRec 'goes to
new record
CustLast = ctrl1
OfficeNo = ctrl2
Officer = ctrl3
Region = ctrl4
Closer = ctrl5

The names before and after the = sign is the name of your field just change
mine to yours. If you follow this it will work perfectly. I used it in three
databases and never had a problem. This is not my code so if you do run into
a problem, I do not know how to fix it.

Good Luck!
 
Gator,
Private Sub controlname_AfterUpdate()
For a text field use: Me.controlname.DefaultValue = """" & Me.controlname &
""""

For a date field use: Me.TheDateControl.DefaultValue = "#" &
Me.TheDateControl & "#"

For a number field use: Me.TheNumberField.DefaultValue = Me.TheNumberField
End Sub

Thus if the user enters XYZ it will set the DefaultValue property to "XYZ"
which will be used for the next entry. When you open the form you must enter
values in the controls and you will be able to see the default values when
you move to the next record.

If you want a subform to inherit a value from the mainform (and don't want
it editable) you can make that field part of the Master/Child Field pair.

Jeanette Cunningham
 
Gator, please don't post a question multiple times in this forum! This
question has been answered for you in both of your threads, which means that
people posting after the solution was posted the first time have wasted time
trying to help you!

--
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