default to previous record?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Sorry if this is a duplicate posting-- I can't find one I thought I posted...

I need help finding a way to have fields in a form default to the previous
record's entry unless typed over. We're taking repeated weather data readings
and the weather doesn't change that much here.

I know there's a way to do this with coding, but I'm a rookie, and would
appreciate any help walking me through this.

Christine
 
This does involve some coding but most of it is cut and paste - just attach
this to the click event of a command button:

Dim rst As Dao.Recordset
Dim fld As Dao.Field
Dim lngCustid As Long
Set rst = Me.RecordsetClone.Clone
Me.RecordsetClone.Bookmark = Me.Bookmark
rst.Bookmark = Me.Bookmark
With Me.RecordsetClone
rst.AddNew
For Each fld In .Fields
'skip the primary key field -
'chg CustomerID to the name of your primary key field
If fld.Name <> "Customerid" Then
rst.Fields(fld.Name).Value = fld.Value
End If
Next fld
' Update the recordset with the new value
rst.Update
rst.Bookmark = rst.LastModified
' set the form's book mark to the new record
Me.Bookmark = rst.Bookmark
End With
Set rst = Nothing
Set fld = Nothing
 
By the 'click event' of a command button, do you mean the "OnClick" property
in the control's property box? Would I just paste this into the Code Builder?
(and is the command button the same as the field's control?)

Thank you!
C



Sandra Daigle said:
This does involve some coding but most of it is cut and paste - just attach
this to the click event of a command button:

Dim rst As Dao.Recordset
Dim fld As Dao.Field
Dim lngCustid As Long
Set rst = Me.RecordsetClone.Clone
Me.RecordsetClone.Bookmark = Me.Bookmark
rst.Bookmark = Me.Bookmark
With Me.RecordsetClone
rst.AddNew
For Each fld In .Fields
'skip the primary key field -
'chg CustomerID to the name of your primary key field
If fld.Name <> "Customerid" Then
rst.Fields(fld.Name).Value = fld.Value
End If
Next fld
' Update the recordset with the new value
rst.Update
rst.Bookmark = rst.LastModified
' set the form's book mark to the new record
Me.Bookmark = rst.Bookmark
End With
Set rst = Nothing
Set fld = Nothing

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Sorry if this is a duplicate posting-- I can't find one I thought I
posted...

I need help finding a way to have fields in a form default to the
previous record's entry unless typed over. We're taking repeated
weather data readings and the weather doesn't change that much here.

I know there's a way to do this with coding, but I'm a rookie, and
would appreciate any help walking me through this.

Christine
 
Go to the OnClick Property of the control you want to use to activate this
code (I was suggesting that you add a command button to do this but you can
put it anywhere you'd like). When you put your cursor in the OnClick
property click the down arrow and select "[Event Procedure]" then click the
build button (". . ."). This will open the Visual Basic editor and put the
cursor into the event procedure for the Click Event. Paste this code into
that procedure. Read through the code first - there is one section you need
to modify to fit your data.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
By the 'click event' of a command button, do you mean the "OnClick"
property in the control's property box? Would I just paste this into the
Code Builder? (and is the command button the same as the field's control?)

Thank you!
C



Sandra Daigle said:
This does involve some coding but most of it is cut and paste - just
attach this to the click event of a command button:

Dim rst As Dao.Recordset
Dim fld As Dao.Field
Dim lngCustid As Long
Set rst = Me.RecordsetClone.Clone
Me.RecordsetClone.Bookmark = Me.Bookmark
rst.Bookmark = Me.Bookmark
With Me.RecordsetClone
rst.AddNew
For Each fld In .Fields
'skip the primary key field -
'chg CustomerID to the name of your primary key field
If fld.Name <> "Customerid" Then
rst.Fields(fld.Name).Value = fld.Value
End If
Next fld
' Update the recordset with the new value
rst.Update
rst.Bookmark = rst.LastModified
' set the form's book mark to the new record
Me.Bookmark = rst.Bookmark
End With
Set rst = Nothing
Set fld = Nothing

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Sorry if this is a duplicate posting-- I can't find one I thought I
posted...

I need help finding a way to have fields in a form default to the
previous record's entry unless typed over. We're taking repeated
weather data readings and the weather doesn't change that much here.

I know there's a way to do this with coding, but I'm a rookie, and
would appreciate any help walking me through this.

Christine
 
Wonderful! Thank you!

Sandra Daigle said:
Go to the OnClick Property of the control you want to use to activate this
code (I was suggesting that you add a command button to do this but you can
put it anywhere you'd like). When you put your cursor in the OnClick
property click the down arrow and select "[Event Procedure]" then click the
build button (". . ."). This will open the Visual Basic editor and put the
cursor into the event procedure for the Click Event. Paste this code into
that procedure. Read through the code first - there is one section you need
to modify to fit your data.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
By the 'click event' of a command button, do you mean the "OnClick"
property in the control's property box? Would I just paste this into the
Code Builder? (and is the command button the same as the field's control?)

Thank you!
C



Sandra Daigle said:
This does involve some coding but most of it is cut and paste - just
attach this to the click event of a command button:

Dim rst As Dao.Recordset
Dim fld As Dao.Field
Dim lngCustid As Long
Set rst = Me.RecordsetClone.Clone
Me.RecordsetClone.Bookmark = Me.Bookmark
rst.Bookmark = Me.Bookmark
With Me.RecordsetClone
rst.AddNew
For Each fld In .Fields
'skip the primary key field -
'chg CustomerID to the name of your primary key field
If fld.Name <> "Customerid" Then
rst.Fields(fld.Name).Value = fld.Value
End If
Next fld
' Update the recordset with the new value
rst.Update
rst.Bookmark = rst.LastModified
' set the form's book mark to the new record
Me.Bookmark = rst.Bookmark
End With
Set rst = Nothing
Set fld = Nothing

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Rabbit wrote:
Sorry if this is a duplicate posting-- I can't find one I thought I
posted...

I need help finding a way to have fields in a form default to the
previous record's entry unless typed over. We're taking repeated
weather data readings and the weather doesn't change that much here.

I know there's a way to do this with coding, but I'm a rookie, and
would appreciate any help walking me through this.

Christine
 
Whooops, finally had time to try this and I couldn't make it go. Please
excuse my ignorance, but if the field name of the control that I want this to
run in is WDIR, in a table called WDAT (AUTONUMBER=PK), would the code look
like this?

Dim rst As Dao.Recordset
Dim fld As Dao.Field
Dim lngCustid As Long
Set rst = Me.RecordsetClone.Clone
Me.RecordsetClone.Bookmark = Me.Bookmark
rst.Bookmark = Me.Bookmark
With Me.RecordsetClone
rst.AddNew
For Each fld In .Fields
'skip the primary key field -
'chg CustomerID to the name of your primary key field
If fld.Name <> "AUTONUMBER" Then
rst.Fields(WDIR).Value = fld.Value
End If
Next fld
' Update the recordset with the new value
rst.Update
rst.Bookmark = rst.LastModified
' set the form's book mark to the new record
Me.Bookmark = rst.Bookmark
End With
Set rst = Nothing
Set fld = Nothing

Also, do I need to enter a value for Recordset, or can it automatically take
it when someone enters data? And do I need to cut out the green text (lines
beginning with a ') in the event procedure when cutting and pasting?

Thank you so much!
Christine


Rabbit said:
Wonderful! Thank you!

Sandra Daigle said:
Go to the OnClick Property of the control you want to use to activate this
code (I was suggesting that you add a command button to do this but you can
put it anywhere you'd like). When you put your cursor in the OnClick
property click the down arrow and select "[Event Procedure]" then click the
build button (". . ."). This will open the Visual Basic editor and put the
cursor into the event procedure for the Click Event. Paste this code into
that procedure. Read through the code first - there is one section you need
to modify to fit your data.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
By the 'click event' of a command button, do you mean the "OnClick"
property in the control's property box? Would I just paste this into the
Code Builder? (and is the command button the same as the field's control?)

Thank you!
C



:

This does involve some coding but most of it is cut and paste - just
attach this to the click event of a command button:

Dim rst As Dao.Recordset
Dim fld As Dao.Field
Dim lngCustid As Long
Set rst = Me.RecordsetClone.Clone
Me.RecordsetClone.Bookmark = Me.Bookmark
rst.Bookmark = Me.Bookmark
With Me.RecordsetClone
rst.AddNew
For Each fld In .Fields
'skip the primary key field -
'chg CustomerID to the name of your primary key field
If fld.Name <> "Customerid" Then
rst.Fields(fld.Name).Value = fld.Value
End If
Next fld
' Update the recordset with the new value
rst.Update
rst.Bookmark = rst.LastModified
' set the form's book mark to the new record
Me.Bookmark = rst.Bookmark
End With
Set rst = Nothing
Set fld = Nothing

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Rabbit wrote:
Sorry if this is a duplicate posting-- I can't find one I thought I
posted...

I need help finding a way to have fields in a form default to the
previous record's entry unless typed over. We're taking repeated
weather data readings and the weather doesn't change that much here.

I know there's a way to do this with coding, but I'm a rookie, and
would appreciate any help walking me through this.

Christine
 
You just want it to skip the Autonum field when copying values from the
previous record. So this is the only change:

If fld.Name <> "WDIR" Then
rst.Fields(fld.name).Value = fld.Value
End If

Dim rst As Dao.Recordset
Dim fld As Dao.Field
Dim lngCustid As Long
Set rst = Me.RecordsetClone.Clone
Me.RecordsetClone.Bookmark = Me.Bookmark
rst.Bookmark = Me.Bookmark
With Me.RecordsetClone
rst.AddNew
For Each fld In .Fields
'skip the primary key field -

If fld.Name <> "WDIR" Then
rst.Fields(fld.name).Value = fld.Value
End If
Next fld
' Update the recordset with the new value
rst.Update
rst.Bookmark = rst.LastModified
' set the form's book mark to the new record
Me.Bookmark = rst.Bookmark
End With
Set rst = Nothing
Set fld = Nothing

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Whooops, finally had time to try this and I couldn't make it go.
Please excuse my ignorance, but if the field name of the control that
I want this to run in is WDIR, in a table called WDAT
(AUTONUMBER=PK), would the code look like this?

Dim rst As Dao.Recordset
Dim fld As Dao.Field
Dim lngCustid As Long
Set rst = Me.RecordsetClone.Clone
Me.RecordsetClone.Bookmark = Me.Bookmark
rst.Bookmark = Me.Bookmark
With Me.RecordsetClone
rst.AddNew
For Each fld In .Fields
'skip the primary key field -
'chg CustomerID to the name of your primary key field
If fld.Name <> "AUTONUMBER" Then
rst.Fields(WDIR).Value = fld.Value
End If
Next fld
' Update the recordset with the new value
rst.Update
rst.Bookmark = rst.LastModified
' set the form's book mark to the new record
Me.Bookmark = rst.Bookmark
End With
Set rst = Nothing
Set fld = Nothing

Also, do I need to enter a value for Recordset, or can it
automatically take it when someone enters data? And do I need to cut
out the green text (lines beginning with a ') in the event procedure
when cutting and pasting?

Thank you so much!
Christine


Rabbit said:
Wonderful! Thank you!

Sandra Daigle said:
Go to the OnClick Property of the control you want to use to
activate this code (I was suggesting that you add a command button
to do this but you can put it anywhere you'd like). When you put
your cursor in the OnClick property click the down arrow and select
"[Event Procedure]" then click the build button (". . ."). This
will open the Visual Basic editor and put the cursor into the event
procedure for the Click Event. Paste this code into that procedure.
Read through the code first - there is one section you need to
modify to fit your data.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Rabbit wrote:
By the 'click event' of a command button, do you mean the "OnClick"
property in the control's property box? Would I just paste this
into the Code Builder? (and is the command button the same as the
field's control?)

Thank you!
C



:

This does involve some coding but most of it is cut and paste -
just attach this to the click event of a command button:

Dim rst As Dao.Recordset
Dim fld As Dao.Field
Dim lngCustid As Long
Set rst = Me.RecordsetClone.Clone
Me.RecordsetClone.Bookmark = Me.Bookmark
rst.Bookmark = Me.Bookmark
With Me.RecordsetClone
rst.AddNew
For Each fld In .Fields
'skip the primary key field -
'chg CustomerID to the name of your primary key field
If fld.Name <> "Customerid" Then
rst.Fields(fld.Name).Value = fld.Value
End If
Next fld
' Update the recordset with the new value
rst.Update
rst.Bookmark = rst.LastModified
' set the form's book mark to the new record
Me.Bookmark = rst.Bookmark
End With
Set rst = Nothing
Set fld = Nothing

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Rabbit wrote:
Sorry if this is a duplicate posting-- I can't find one I
thought I posted...

I need help finding a way to have fields in a form default to the
previous record's entry unless typed over. We're taking repeated
weather data readings and the weather doesn't change that much
here.

I know there's a way to do this with coding, but I'm a rookie,
and would appreciate any help walking me through this.

Christine
 
Back
Top