?
Solved

numbering checking

Posted on 2003-12-11
13
Medium Priority
?
257 Views
Last Modified: 2010-05-01
I have a form that displays information of courses. So when I click one of the courses I want to print a certificate for it. My question is how can I make this number to increase. I want to start the first certificate to print like this 0001 and the next one will increase like 0002, etc.
So my question is: how can I go and check the last certificate printed to my access database and then print the next one?

thank you for your help...

0
Comment
Question by:mapy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 42

Expert Comment

by:frodoman
ID: 9921830
I assume you have a table where you store the certificates after printing them?  

It should be a matter of doing SELECT MAX(CertNumber) FROM CertTable, then adding 1 to this number and inserting a new record into the table.

0
 
LVL 9

Expert Comment

by:Dang123
ID: 9921988
mapy,
    frodoman is correct, also if you are keeping information for more than one type of certificate in your table, you can add the WHERE clause making it :

SELECT MAX(CertNumber) FROM CertTable WHERE CertType = "Computer Science"

Dang123

0
 
LVL 17

Expert Comment

by:inthedark
ID: 9922035
If you are using a table which contains your certificate details add an AutoNumber field to the record.  You can then use this field as it will always be unique. I expect you already have an autonumber field.  I would also add another field say called Printed.



' open your certificate records.

SQL = "Select * From [MyTable] Where ([Printed]=False);"
Set RS = DB.OpenRecordSet(SQL, dbOpenDynaset, DbSeeChanges)


' loop until all have been printed
Do While Not Rs.Eof

    'Print the cretificates
    PrintCert RS("MyAutoNumberField") ' call a sub to print the certificate
   ' PrintCert RS ' or you could pass the recordset to the subroutine.
   
   ' No mark the record as printed.
   WorkSpaces(0).BeginTrans
   RS.Edit
   RS("Printed") = True
   RS.Update
   Workspaces(0).Committrans

   RS.MoveNext
Loop
   
Hope this helps~)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:Ficus
ID: 9922258
Those suggestions are correct.  If you are using a access data base you could use the primary key as an auto number and ensure that you keep a proper consecutice series of numbers with no jumps or duplicates.
0
 

Author Comment

by:mapy
ID: 9922638
Hi guys, help me out a little bit more.
I have done this:
Dim strCheck As String
Dim strGetNumber As String
Dim strCertificateNum As String
Dim rsMax As ADODB.Recordset
Set rsMax = New ADODB.Recordset
       
        strCheck = "SELECT MAX(Certificate) FROM Course_Registration"
        With rsMax
            .Open strCheck, cnConn, adOpenKeyset, adLockOptimistic
            If Not .EOF Then
                strGetNumber = .Fields("Certificate")
            Else
                strGetNumber = "SN001"
            End If
            .Close
        End With
        Set rsMax = Nothing
        strGetNumber = Replace(strGetNumber, "SN", 0)
        strCertificateNum = "SN00" & (strGetNumber + 1)
        Text1.Text = strCertificateNum


and i'm getting an error message: 3265 "Item cannot be found in the collection corresponding to the requested name or ordinal." and it points to this line "strGetNumber = .Fields("Certificate")"
any suggestions.
thank you again.

0
 
LVL 9

Expert Comment

by:Dang123
ID: 9922742
The query is returning a single value, the highest number in the "Certificate" column. I beleave it would be named "MAX(Certificate)" or something similar. You can use AS to rename the column if you would like.
0
 

Author Comment

by:mapy
ID: 9922964
doesn't work dang123. i get the same error.
0
 
LVL 42

Expert Comment

by:frodoman
ID: 9923055
Try

strGetNumber = .Fields(1)
0
 
LVL 42

Expert Comment

by:frodoman
ID: 9923079
You may also want to consider replacing this:

strCertificateNum = "SN00" & (strGetNumber + 1)

With this:

strCertificateNum = "SN" & right("000" & (strGetNumber + 1),4)


This way you won't have to change your code when you reach 100 and again when you reach 1000.
0
 

Author Comment

by:mapy
ID: 9923162
Frudo,
why you replace the field customer to 1? i tried and i still get the same error.
after you guys doing the qry: "select max(certificate) from table" how do you assign the biggest number to a variable? You have to open your table and assign it. how do you do it? Thanks a million for your help.
0
 

Author Comment

by:mapy
ID: 9923173
thank you Frudo for the extra codding correction of trimming. I'll use it. thank you!
0
 
LVL 42

Accepted Solution

by:
frodoman earned 2000 total points
ID: 9923241
Actually I think it should be strGetNumber = .Fields(0)  <-- Meaning the first field retrieved instead of referencing by name.

If you want to use a name, change your sql to

 strCheck = "SELECT MAX(Certificate) AS Certificate FROM Course_Registration"

and then leave the other line as: strGetNumber = .Fields("Certificate")
0
 

Author Comment

by:mapy
ID: 9923660
it worked frodoman!!   I had to write: AS certificate.

Thank you all you guys for your help.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question