R
r. howell
I am trying to get a button to work to add a new record. The glitch is that
I want certain fields to be duplicated, since from the point of view of the
user, they are adding a row between two other rows. Since opening a new
record navigates them away from the original data, I want to do two things:
1) Give them the reference data from the row above the place where
they want to insert the data.
2) I have a field (which is my primary key for the data) which is a
number meant to keep these rows in order during normal functioning of the
form which simulates a spreadsheet. My idea was to tell the button to set
default values of the fields I want duplicated to the values of the record
the person is at when they click on the "Add Item" button, set the default
value of the order number to the previous value plus .0001 and go to a new
record. This would give me lots of room for people to put records between
other records without being too likely to mess up, though it's clearly not
perfect.
My code is doing a beautiful job of duplicating most of the fields and
bringing the user to a new record. But I can't even get it to duplicate the
OrderNo, let alone change it. Whatever I do, that number is set to zero in
the new record. This used to be a primary key, but I even took that
constraint off the original table, with fear and trembling, and it still
doesn't work.
Here's my code:
Private Sub Command30_Click()
'This is to allow the new record to be something that can be edited
Dim NewOrdNo As Variant
NewOrdNo = Me.OrderNo.Value + 0.0001
Me.SubReq.DefaultValue = Chr$(34) & Me.SubReq.Value & Chr$(34)
Me.Div.DefaultValue = Chr$(34) & Me.Div.Value & Chr$(34)
Me.C.DefaultValue = Chr$(34) & Me.C.Value & Chr$(34)
Me.OrderNo.DefaultValue = Chr$(34) & NewOrdNo & Chr$(34)
DoCmd.GoToRecord , , acNewRec
End Sub
Thanks for any help you can give me.
I want certain fields to be duplicated, since from the point of view of the
user, they are adding a row between two other rows. Since opening a new
record navigates them away from the original data, I want to do two things:
1) Give them the reference data from the row above the place where
they want to insert the data.
2) I have a field (which is my primary key for the data) which is a
number meant to keep these rows in order during normal functioning of the
form which simulates a spreadsheet. My idea was to tell the button to set
default values of the fields I want duplicated to the values of the record
the person is at when they click on the "Add Item" button, set the default
value of the order number to the previous value plus .0001 and go to a new
record. This would give me lots of room for people to put records between
other records without being too likely to mess up, though it's clearly not
perfect.
My code is doing a beautiful job of duplicating most of the fields and
bringing the user to a new record. But I can't even get it to duplicate the
OrderNo, let alone change it. Whatever I do, that number is set to zero in
the new record. This used to be a primary key, but I even took that
constraint off the original table, with fear and trembling, and it still
doesn't work.
Here's my code:
Private Sub Command30_Click()
'This is to allow the new record to be something that can be edited
Dim NewOrdNo As Variant
NewOrdNo = Me.OrderNo.Value + 0.0001
Me.SubReq.DefaultValue = Chr$(34) & Me.SubReq.Value & Chr$(34)
Me.Div.DefaultValue = Chr$(34) & Me.Div.Value & Chr$(34)
Me.C.DefaultValue = Chr$(34) & Me.C.Value & Chr$(34)
Me.OrderNo.DefaultValue = Chr$(34) & NewOrdNo & Chr$(34)
DoCmd.GoToRecord , , acNewRec
End Sub
Thanks for any help you can give me.