Solved

numbering checking

Posted on 2003-12-11
13
248 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
  • 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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 500 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now