Insert field from previous record

G

Guest

My dbase has a form with a subform. In the subform you enter the beginning
mileage and ending mileage of a vehicle every month (along with other
things). How can I make it to where when I choose to add a new record (the
next month's data for a vehicle) that the ending mileage from the previous
month is automatically inserted into the new records beginning mileage field
for the current month?
 
S

Steve

Assuming the beginning mileage field on your form is named BeginningMileage
and the ending mileage field is named EndingMileage, put the following code
in the AfterUpdate event of the ending mileage field:
Me!BeginningMileage.DefaultValue = Me!EndingMileage

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
 
G

Guest

I tried the code you mentioned and nothing happened. Below is what I entered
in the AfterUpdate event within the Ending Mileage field of the subform:

Private Sub Ending_Mileage_AfterUpdate()
Me!Beginning Mileage.DefaultValue = Me!Ending Mileage
End Sub

The middle line of this code stayed red. I took the space out between both
beginning mileage and ending mileage and the line went back to normal black
but the code still didn't work. I checked the table where the fields are
stored and the two mileage fields are spelled exactly as in the above code.

Any suggestions?
 
D

Douglas J. Steele

Because your field names have spaces in them (seldom a good idea, btw), you
need to enclose them in square brackets. And even if the field is numeric,
the DefaultValue property is text, and so want quotes:

Me![Beginning Mileage].DefaultValue = Chr$(34) & Me![Ending Mileage] &
Chr$(34)
 
S

Steve

Ending_Mileage indicates that the field name on your form is Ending_Mileage
with an underline and no space between the words. Open
your form in design view and select the Beginning Mileage field. Open
properties and go to the Other tab. Is the name of this field
Beginning_Mileage? Also, Doug is right about the quotes. Your line of code
should be:
Me!Beginning_Mileage.DefaultValue = Chr$(34) & Me!Ending_Mileage & Chr$(34)

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
 
D

Douglas J. Steele

Ending_Mileage indicates that the field name on your form is
Ending_Mileage
with an underline and no space between the words.

No, it doesn't necessarily mean that. If the field is named Ending Mileage
(with a space), the procedure generated for the field will be:

Private Sub Ending_Mileage_AfterUpdate()

(Try it and see)
 
G

Guest

Here is what I have now in the AfterUpdate event of the Ending Mileage field.

Private Sub Ending_Mileage_AfterUpdate()
Me![Beginning Mileage].DefaultValue = Chr$(34) & Me![Ending Mileage] &
Chr$(34)
End Sub

It appears the code is accurate because it's not red anymore but the result
is the same, nothing happens when I select a new record to add.

Am I correct in saying what should happen with this code is when I select a
new record for the next month on a vehicle, the Beginning Mileage will
automatically populate with the most recent ending mileage entered? This
is the way I hoped it would work. Sorry for the trouble!
 
D

Douglas J. Steele

Check that you haven't defined a default value (usually 0) for the field in
the table.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Todd said:
Here is what I have now in the AfterUpdate event of the Ending Mileage
field.

Private Sub Ending_Mileage_AfterUpdate()
Me![Beginning Mileage].DefaultValue = Chr$(34) & Me![Ending Mileage] &
Chr$(34)
End Sub

It appears the code is accurate because it's not red anymore but the
result
is the same, nothing happens when I select a new record to add.

Am I correct in saying what should happen with this code is when I select
a
new record for the next month on a vehicle, the Beginning Mileage will
automatically populate with the most recent ending mileage entered?
This
is the way I hoped it would work. Sorry for the trouble!

--
Todd


Douglas J. Steele said:
No, it doesn't necessarily mean that. If the field is named Ending
Mileage
(with a space), the procedure generated for the field will be:

Private Sub Ending_Mileage_AfterUpdate()

(Try it and see)
 
S

Steve

Doesn't a field default value in a form override the default value in the
table?

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)



Douglas J. Steele said:
Check that you haven't defined a default value (usually 0) for the field
in the table.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Todd said:
Here is what I have now in the AfterUpdate event of the Ending Mileage
field.

Private Sub Ending_Mileage_AfterUpdate()
Me![Beginning Mileage].DefaultValue = Chr$(34) & Me![Ending Mileage] &
Chr$(34)
End Sub

It appears the code is accurate because it's not red anymore but the
result
is the same, nothing happens when I select a new record to add.

Am I correct in saying what should happen with this code is when I select
a
new record for the next month on a vehicle, the Beginning Mileage will
automatically populate with the most recent ending mileage entered? This
is the way I hoped it would work. Sorry for the trouble!

--
Todd


Douglas J. Steele said:
Ending_Mileage indicates that the field name on your form is
Ending_Mileage
with an underline and no space between the words.

No, it doesn't necessarily mean that. If the field is named Ending
Mileage
(with a space), the procedure generated for the field will be:

Private Sub Ending_Mileage_AfterUpdate()

(Try it and see)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ending_Mileage indicates that the field name on your form is
Ending_Mileage
with an underline and no space between the words. Open
your form in design view and select the Beginning Mileage field. Open
properties and go to the Other tab. Is the name of this field
Beginning_Mileage? Also, Doug is right about the quotes. Your line of
code
should be:
Me!Beginning_Mileage.DefaultValue = Chr$(34) & Me!Ending_Mileage &
Chr$(34)

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)







I tried the code you mentioned and nothing happened. Below is what I
entered
in the AfterUpdate event within the Ending Mileage field of the
subform:

Private Sub Ending_Mileage_AfterUpdate()
Me!Beginning Mileage.DefaultValue = Me!Ending Mileage
End Sub

The middle line of this code stayed red. I took the space out
between
both
beginning mileage and ending mileage and the line went back to normal
black
but the code still didn't work. I checked the table where the
fields
are
stored and the two mileage fields are spelled exactly as in the above
code.

Any suggestions?

--
Todd


:

Assuming the beginning mileage field on your form is named
BeginningMileage
and the ending mileage field is named EndingMileage, put the
following
code
in the AfterUpdate event of the ending mileage field:
Me!BeginningMileage.DefaultValue = Me!EndingMileage

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)



My dbase has a form with a subform. In the subform you enter the
beginning
mileage and ending mileage of a vehicle every month (along with
other
things). How can I make it to where when I choose to add a new
record
(the
next month's data for a vehicle) that the ending mileage from the
previous
month is automatically inserted into the new records beginning
mileage
field
for the current month?
 
G

Guest

I checked and there is no default value in the beginning mileage or ending
mileage fields within the form or table fields. The data type in the table
for both fields is Number, the field size is Long Integer, the format is
Standard, decimal places is 0, Required is No, and Indexed is No in case this
helps.
--
Todd


Douglas J. Steele said:
Check that you haven't defined a default value (usually 0) for the field in
the table.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Todd said:
Here is what I have now in the AfterUpdate event of the Ending Mileage
field.

Private Sub Ending_Mileage_AfterUpdate()
Me![Beginning Mileage].DefaultValue = Chr$(34) & Me![Ending Mileage] &
Chr$(34)
End Sub

It appears the code is accurate because it's not red anymore but the
result
is the same, nothing happens when I select a new record to add.

Am I correct in saying what should happen with this code is when I select
a
new record for the next month on a vehicle, the Beginning Mileage will
automatically populate with the most recent ending mileage entered?
This
is the way I hoped it would work. Sorry for the trouble!

--
Todd


Douglas J. Steele said:
Ending_Mileage indicates that the field name on your form is
Ending_Mileage
with an underline and no space between the words.

No, it doesn't necessarily mean that. If the field is named Ending
Mileage
(with a space), the procedure generated for the field will be:

Private Sub Ending_Mileage_AfterUpdate()

(Try it and see)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ending_Mileage indicates that the field name on your form is
Ending_Mileage
with an underline and no space between the words. Open
your form in design view and select the Beginning Mileage field. Open
properties and go to the Other tab. Is the name of this field
Beginning_Mileage? Also, Doug is right about the quotes. Your line of
code
should be:
Me!Beginning_Mileage.DefaultValue = Chr$(34) & Me!Ending_Mileage &
Chr$(34)

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)







I tried the code you mentioned and nothing happened. Below is what I
entered
in the AfterUpdate event within the Ending Mileage field of the
subform:

Private Sub Ending_Mileage_AfterUpdate()
Me!Beginning Mileage.DefaultValue = Me!Ending Mileage
End Sub

The middle line of this code stayed red. I took the space out between
both
beginning mileage and ending mileage and the line went back to normal
black
but the code still didn't work. I checked the table where the fields
are
stored and the two mileage fields are spelled exactly as in the above
code.

Any suggestions?

--
Todd


:

Assuming the beginning mileage field on your form is named
BeginningMileage
and the ending mileage field is named EndingMileage, put the
following
code
in the AfterUpdate event of the ending mileage field:
Me!BeginningMileage.DefaultValue = Me!EndingMileage

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)



My dbase has a form with a subform. In the subform you enter the
beginning
mileage and ending mileage of a vehicle every month (along with
other
things). How can I make it to where when I choose to add a new
record
(the
next month's data for a vehicle) that the ending mileage from the
previous
month is automatically inserted into the new records beginning
mileage
field
for the current month?
 
D

Douglas J. Steele

Sorry, no idea why it's not working for you.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Todd said:
I checked and there is no default value in the beginning mileage or ending
mileage fields within the form or table fields. The data type in the
table
for both fields is Number, the field size is Long Integer, the format is
Standard, decimal places is 0, Required is No, and Indexed is No in case
this
helps.
--
Todd


Douglas J. Steele said:
Check that you haven't defined a default value (usually 0) for the field
in
the table.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Todd said:
Here is what I have now in the AfterUpdate event of the Ending Mileage
field.

Private Sub Ending_Mileage_AfterUpdate()
Me![Beginning Mileage].DefaultValue = Chr$(34) & Me![Ending Mileage] &
Chr$(34)
End Sub

It appears the code is accurate because it's not red anymore but the
result
is the same, nothing happens when I select a new record to add.

Am I correct in saying what should happen with this code is when I
select
a
new record for the next month on a vehicle, the Beginning Mileage will
automatically populate with the most recent ending mileage entered?
This
is the way I hoped it would work. Sorry for the trouble!

--
Todd


:

Ending_Mileage indicates that the field name on your form is
Ending_Mileage
with an underline and no space between the words.

No, it doesn't necessarily mean that. If the field is named Ending
Mileage
(with a space), the procedure generated for the field will be:

Private Sub Ending_Mileage_AfterUpdate()

(Try it and see)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ending_Mileage indicates that the field name on your form is
Ending_Mileage
with an underline and no space between the words. Open
your form in design view and select the Beginning Mileage field.
Open
properties and go to the Other tab. Is the name of this field
Beginning_Mileage? Also, Doug is right about the quotes. Your line
of
code
should be:
Me!Beginning_Mileage.DefaultValue = Chr$(34) & Me!Ending_Mileage &
Chr$(34)

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)







I tried the code you mentioned and nothing happened. Below is what
I
entered
in the AfterUpdate event within the Ending Mileage field of the
subform:

Private Sub Ending_Mileage_AfterUpdate()
Me!Beginning Mileage.DefaultValue = Me!Ending Mileage
End Sub

The middle line of this code stayed red. I took the space out
between
both
beginning mileage and ending mileage and the line went back to
normal
black
but the code still didn't work. I checked the table where the
fields
are
stored and the two mileage fields are spelled exactly as in the
above
code.

Any suggestions?

--
Todd


:

Assuming the beginning mileage field on your form is named
BeginningMileage
and the ending mileage field is named EndingMileage, put the
following
code
in the AfterUpdate event of the ending mileage field:
Me!BeginningMileage.DefaultValue = Me!EndingMileage

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And
Word
Applications
(e-mail address removed)



My dbase has a form with a subform. In the subform you enter
the
beginning
mileage and ending mileage of a vehicle every month (along with
other
things). How can I make it to where when I choose to add a new
record
(the
next month's data for a vehicle) that the ending mileage from
the
previous
month is automatically inserted into the new records beginning
mileage
field
for the current month?
 

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