Link to home
Start Free TrialLog in
Avatar of mapy
mapy

asked on

numbering checking

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

Avatar of frodoman
frodoman
Flag of United States of America image

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.

Avatar of Dang123
Dang123

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

Avatar of inthedark
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~)
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.
Avatar of mapy

ASKER

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.

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.
Avatar of mapy

ASKER

doesn't work dang123. i get the same error.
Try

strGetNumber = .Fields(1)
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.
Avatar of mapy

ASKER

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.
Avatar of mapy

ASKER

thank you Frudo for the extra codding correction of trimming. I'll use it. thank you!
ASKER CERTIFIED SOLUTION
Avatar of frodoman
frodoman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mapy

ASKER

it worked frodoman!!   I had to write: AS certificate.

Thank you all you guys for your help.