putting data from table to form with vba

michalgut25

Registered User.
Local time
Today, 11:25
Joined
Jan 28, 2013
Messages
15
I'm looking for three days solution and I can't find. I'm beginner in access so it is too hard for me. Please help me!
I will put this code in "On load" on my form.
This code should add a new record in OrderTab, take a number from AutoNumber, then plus text from "year" column in the same table (there is default value) and past into Me![Order_number]

Example
1)new AutoNumber is 8
2)+"/13" - text from "year" column which is defaullt value
3) past 8/13 to Me![Order_number]
 
Last edited:
Hi,
1. Me![Order_number]=OrderNumber
2. Are you realy soure you want create a new order for each time the form is opend? I suggest you think of a better method.
Good luck!
 
Yes I have special button "write new order" to open form.
Marlan this is all of code? I read something about "variable", "dim", "dbs.OpenRecordset" but I don't know how to put into a code correctly. What about plus text from "year" column?
Me![Order_number]=OrderNumber - this will create new record in OrderTab?

I corrected my last post - I wrote it after waking up;)
 
Last edited:
Let me first understand your problem.
1. Are the AutoNumber and the Order_Number Fields in the same table?
2. Is this same table the recordsource of the form?
 
1. No. Order_number is field in my open form, AutoNumber is column in table "OrderTab"
2. Actually Form is unnbound (It must be unbound) but in this example I have only one table - OrderTab and only one form.. So this table is a recordsource of the form.
 
Hi,
Your new AutoNumber will allwase be the highest in the table. To get it you could use:
Code:
dim rst as DAO.RecordSet
dim strSQL as string
strSQL = "SELCET MAX(AutoNumber) FROM tableName"
set rst = CurrentDB.OpenRecordSet(strSQL)
Me![Order_number]=me.Year & rst.Fields(0)
BUT,
Think if you need this code: use a bound form, and have DataEntryproperty set to true. The user will enter the new order, and you can have some other event some other event handler (On Close?) take the AutoNumber from the field on the form and create the order ID.
BTW, how do you reset AutoNumber coming 2014? or maybe I misunderstood your process... in that case the code above is not relevant either...
How is AutoNumber created?​
 
Last edited:
Thanks for insight
Doesn't work - attached screen.
I change column name from "year" to "years" cause was resserved by access.
I use unbound form, with subforms. It is complicated but I try to build unbound form to data entry, to fill tables with relationship. I can't find any solutions on the internet so I try on my own. Everybody write that unbound form is best way to protect data, but nobody write how to put the data in linked tables , so now I learn:)
I use this function =Right(Year(Date());2) so I have correct date all the time.
 

Attachments

  • 1.jpg
    1.jpg
    64.1 KB · Views: 92

Users who are viewing this thread

Back
Top Bottom