Button for Adding New Record

G

Guest

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 really want to get this code working
for my friends so that I can move on to other things with a smile on my face.
 
G

Guest

Have you tried openargs?
I am not familiar with the concept but i think it may help. give it a look.


"r. howell" escreveu:
 
G

Guest

Thanks for trying, but no, this does not help.

Raul Sousa said:
Have you tried openargs?
I am not familiar with the concept but i think it may help. give it a look.


"r. howell" escreveu:
 
J

J. Goddard

Hi -

NewOrdNo is a numeric, and presumably it is numeric in the data table as
well; why are you putting quotes around it?

In the underlying table that you are adding to, what is the data type of
the orderNO?

John
 

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