Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 March 16th, 2005, 08:08 PM
Authorized User
 
Join Date: Mar 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default why the autonumber cant display as what i have set

hi,

I have put the format of an autonumber as "A0000" , in the table the results are "A0001, A0002 ....(and so on)" when i bound to a form it will display only "1, 2 ... (and so on)". Why i cannot get the display of "A0001" in the form? Actually my purpose is to let access generate a document number for each record. or if there is another way to generate a document number in stead?
Anyone can help me plz..?
Thanks !
 
Old March 18th, 2005, 01:02 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Generate the document number in your queries, or forms and reports, not in the table. The PK of a table should NEVER be meaningful data.

mmcdonal
 
Old March 20th, 2005, 06:52 AM
Authorized User
 
Join Date: Mar 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is good practice to create a table only for the purpose of numbering documents, and there you might use an extra field for text identification.

It sounds redunctant, yet you should give it a try.




 
Old March 20th, 2005, 08:18 PM
Authorized User
 
Join Date: Mar 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your replies

 
Old March 22nd, 2005, 09:07 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

To elaborate on what mmcdonal said, an autonumber (used as a primary key, i.e. PK) in a table is of type long integer and is created by the computer. It does not have any real meaning other than reference the record in question and relate it to other records in other tables. Users never see it. It works behind the scenes.

"A0001" is of type string and it seems to hold some meaning people want to see in reports and forms. Therefore it is NOT an autonumber. It's just a label that is consecutively numbered. In queries, you can find out what is next in line by using the DMAX function and adding one to the numerical portion of the label.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old March 22nd, 2005, 09:00 PM
Authorized User
 
Join Date: Mar 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you SerranoG

 
Old March 22nd, 2005, 11:11 PM
Authorized User
 
Join Date: Mar 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have successfully generated the continuously number by using Dmax function, but i dont know how to set the format to "A00001"..
anyone can help me plz?

the function looks like this:
--------------------------------------------------------------------------------------------------------------------------------
Public Function GetNextNum() As Long
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim lngCurNum As Long

    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT [DocNo] FROM [receive] ORDER BY [DocNo] ", dbOpenSnapshot)

    With rs
        .MoveNext
        GetNextNum = DMax("DocNo", "receive") + 1
    End With

exit_Routine:
    Set rs = Nothing
    Set db = Nothing
    Exit Function

err_Routine:
    MsgBox Err.Description
    Resume exit_Routine

End Function
--------------------------------------------------------------------------------------------------------------------------------

thanks a lotz...

 
Old March 23rd, 2005, 04:50 PM
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

To get a number into the format "A00001" you have to use the FORMAT statement.

GetNextNum = DMax("DocNo", "receive") + 1
NewDocNo = "A" & Format(GetNextNum, "00000")




Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old March 24th, 2005, 12:00 AM
Authorized User
 
Join Date: Mar 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks SerranoG..

Now I have applied the NewDocNo, but i got the error 13 : type mismatch.

NewDocNo = DMax("DocNo", "receive") + 1
GetNextNum = "A" + Format(NewDocNo, "00000")

I declare the GetNextNum and NewDocNo as Variant.
the code is doing well without the "A" in the NewDocNo .
my DocNo in the table is Text.
What is my mistake here?

Thanks ...


 
Old March 24th, 2005, 08:45 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

Quote:
quote:Originally posted by utarian
Now I have applied the NewDocNo, but i got the error 13 : type mismatch.

NewDocNo = DMax("DocNo", "receive") + 1
GetNextNum = "A" + Format(NewDocNo, "00000")

What is my mistake here?
Your mistake is that you got it backwards. You assigned the number to NewDocNo and the label to GetNextNum. Reverse that, i.e.

GetNextNum = DMax("DocNo", "receive") + 1
NewDocNo = "A" + Format(GetNextNum, "00000")


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
AutoNumber causes problem. myself Classic ASP Professional 1 July 10th, 2006 03:35 PM
AutoNumber field tulincim Access 5 June 6th, 2006 03:44 PM
AutoNumber Hell somissac Access VBA 5 March 22nd, 2005 04:05 AM
Autonumber display in form field ianc Access 2 January 14th, 2005 07:11 AM
regarding Autonumber... MuthuAL Classic ASP Databases 2 December 8th, 2004 08:04 AM





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