Keeping an input on a field the same after it's been submitted

1992

Registered User.
Local time
Today, 19:32
Joined
Aug 10, 2011
Messages
18
Basically, I have an input on my form which is related to a field and most of the time (2/3 of the time I'd guess), the person using the form will have to type a 9 digit number in but this number varies with no pattern so setting the field's default value is no help.

Is there a way to make it on my form so that this field will by default stay the same as what was previously entered?
 
You can likely manage it, but keep in mind that as soon as you start entering data (or some code enters it for you) the record is created, the values of Now() and Date() are calculated and autonumbers are assigned.

This could cause your records to have dates hours before they were actually input (assuming the user sits there for hours before inputting the rest of the data), the autonumbers can go out of order, etc.

Please make sure that's not going to cause problems before deciding if you want to proceed. :)
 
You can likely manage it, but keep in mind that as soon as you start entering data (or some code enters it for you) the record is created, the values of Now() and Date() are calculated and autonumbers are assigned.

This could cause your records to have dates hours before they were actually input (assuming the user sits there for hours before inputting the rest of the data), the autonumbers can go out of order, etc.

Please make sure that's not going to cause problems before deciding if you want to proceed. :)


It's nothing to do with dates - it's basically a product code but the first 9 digits are usually the same for similar products and so the person processing the products would have to type these 9 letters out again for 20 products or so. It would be easier if the previous entry stayed there after the record had been saved so the operator can just modify the last 4 digits rather than typing out the 9 digit string again. There's not going to be a problem with dates being in the wrong place - what I meant was that there's no real pattern to the numbers so I can't create a formula for the default value to be there as I have no way of knowing what the code will be.

Do you think I can achieve that?
 
I wasn't refering to that specific field, just to the fact that populating ANY bound control in a bound form (therefor inputting into ANY field in the table) results in all fields with default values (such as dates) to be populated.

So if you have a field called "RecordCreationDate" which has a default value of Now() then that field will actually hold the time when the previous record was created (as that's when it then moves to a new record and the new piece of code inputs the previous 9 digit code into the new record).

Assuming you're happy with that it's just a case of modifying the VBA behind the command button which you currently use to save the record and move to a new one.

Something like this:

Code:
dim strPrevProdCode as string
strPrevProdCode = txtProductCode
 
'CURRENT CODE FOR SAVING / MOVING RECORD HERE
 
txtProductCode = strPrevProdCode
 
I wasn't refering to that specific field, just to the fact that populating ANY bound control in a bound form (therefor inputting into ANY field in the table) results in all fields with default values (such as dates) to be populated.

So if you have a field called "RecordCreationDate" which has a default value of Now() then that field will actually hold the time when the previous record was created (as that's when it then moves to a new record and the new piece of code inputs the previous 9 digit code into the new record).

Assuming you're happy with that it's just a case of modifying the VBA behind the command button which you currently use to save the record and move to a new one.

Something like this:

Code:
dim strPrevProdCode as string
strPrevProdCode = txtProductCode
 
'CURRENT CODE FOR SAVING / MOVING RECORD HERE
 
txtProductCode = strPrevProdCode

I made a simple button and the VBA in the OnClick property is:

Code:
Dim strPrevProductID As String
strPrevProductID = txtProductCode
    DoCmd.GoToRecord , "", acNewRec
txtProductCode = strPrevProductID

The field which I want updated is ProductCode. This button will add a new blank record fine but it doesn't fill in the field :/
 
The textbox on the form which holds the product code is called "txtProductCode"?
 
The textbox on the form which holds the product code is called "txtProductCode"?


Ohhh OK I don't really know VBA so I presumed the txt was part of the script.. it works now I've taken the "txt" out, thanks a lot :D
 
txt is the generally accepted prefix for an textbox control's name.

If you don't use VBA much you can get by with field names / "Combo123" or whatever default names you get when you add a control.

But if you use VBA a lot it's a good idea to ensure you can easily tell what the name relates to.

The same reason the string the VBA creates has the prefix str.

It's not the end of the world if you don't follow a specifric naming convention, but it makes it harder if anyone else has to edit your database (if you move to a new role or someone else works with you, etc).
 
txt is the generally accepted prefix for an textbox control's name.

If you don't use VBA much you can get by with field names / "Combo123" or whatever default names you get when you add a control.

But if you use VBA a lot it's a good idea to ensure you can easily tell what the name relates to.

The same reason the string the VBA creates has the prefix str.

It's not the end of the world if you don't follow a specifric naming convention, but it makes it harder if anyone else has to edit your database
Ohh OK, I see. This is mostly just for myself but I'll bear it in mind.. I know what you mean about being consistent as I had to modify an exising database a few days ago and none of it was clear and there were no comments in any of the code to help me out.

(if you move to a new role or someone else works with you, etc).
Well I'm here on work experience and don't think I'll get promoted in the next 3 weeks :p I came to this company as I'm doing an engineering degree and it's a manufacturing company so I thought I'd get some relevant experience, but most of what I've done has been fiddling with numbers in Excel and Access so I doubt I'll come back next summer.


Edit: I think most of my questions here are the sort of thing I wouldn't need to ask if I had any knowledge of databse theory and how to use relationships properly.
 

Users who are viewing this thread

Back
Top Bottom