Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2010, 08:51 AM
Authorized User
 
Join Date: Dec 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default Booking number help

[FONT='Verdana','sans-serif']Hi,

I have an Access form linked to a table where the key in the table is an autonumber field. My table field is sno(autonumber,PK), name, rdate, order_number now my problems is When adding a new record to the table using the form I want insert into order_number field if rade is now() e.g. “A +sno” like “A001,A002,A003….” next day adding a new record I want from starting like “A001….”
[/FONT]
__________________
Mohamed Mohiddin
Officer

Last edited by mohiddin52; May 5th, 2010 at 10:32 AM..
 
Old May 5th, 2010, 10:37 AM
Authorized User
 
Join Date: Dec 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default Booking number

I have an Access form linked to a table where the key in the table is an autonumber field. My table field is sno(autonumber,PK), name, rdate, order_number now my problems is When adding a new record to the table using the form I want insert into order_number field if rade is now() e.g. “A +sno” like “A001,A002,A003….” next day adding a new record I want from starting like “A001….”
__________________
Mohamed Mohiddin
Officer
 
Old May 14th, 2010, 11:11 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

I understand what it is you want, but my advice is do NOT use the autonumber field "sno" for anythying. Autonumbers are generated by the computer and only have meaning behind the scenes to link a primary key to a foreign key. Autonumbers should not be used in calculations or concatenations for anything.

That said, if you want to use an order number that starts at no. 1 each day, that's not hard to do. I assume that you have one table with the companies and their info, including an autonumber for each record, say "sno." I also assume you have a second table for orders, e.g. "Orders", where you have a foreign key "sno" that links many orders to each company via "sno." In this order table you have a date the order was placed.called "rdate."

You can do something like this for the order number as you enter them into the second table via a subform. Note that Now() has a time associated with it. If you don't care what time it is, use Date().

Code:
If DCount("[sno]","Orders","[sno] = " & Me.sno & " And [RDate] = #" & Date() & "#") = 0 Then
    'There are no orders for sno today.
    Me.Order_Number = "A001"
Else
    'There are orders existing for today for sno.
    Me.Order_Number = "A" & CInt(Right(DMax("[Order_Number]","Orders","[Sno] = " & Me.sno & " And [RDate] = #" & Date() & "#"), 3)) + 1
End If
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation For Phone Number and Mobile Number dhruthi.ram99 Javascript How-To 12 October 30th, 2011 07:24 AM
How to add a line number/Row number- need to use it for page breaks naijacoder XSLT 7 September 27th, 2009 09:42 PM
Appointment Booking KDSTECH BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 11 May 29th, 2008 12:46 AM
booking form LITOTES PHP How-To 2 June 4th, 2003 03:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.