-
Not my best work (did it quickly in 10 mins or so) but it should give you an idea as to what to do.
Must go sleep now! Did not sleep last night!
[vba]Private Sub myButton_Click()
Dim myDB As DAO.Database
Dim myRst As DAO.Recordset
Dim CharAlpha As Integer, ZEndNum As Integer, itemNum As Integer
Dim Zend As String, EndAlpha As String
Set myDB = CurrentDb()
'Set table to add records to
Set myRst = myDB.OpenRecordset("Table1")
CharAlpha = 97
Zend = ""
ZEndNum = 97
itemNum = Me.itemNumber
For i = 1 To Me.txtTickets
'This sets the string to be added to the end of ItemNumber
'Char(97) = a --> Char(122)= z (LOWER CASE)
EndAlpha = Zend & Chr(CharAlpha)
With myRst
'Add new record
.AddNew
'Set value of Field2
.Fields("Field2") = itemNum & EndAlpha
'update record. Must be done to save record
.Update
End With
'increase by 1 for next alphabet
CharAlpha = CharAlpha + 1
'This will allow for a two-character ending.
'e.g after z comes aa, ab and so on...
'so you can have up to (26*26) + 26 records
If CharAlpha > 122 Then
Zend = Chr(ZEndNum)
ZEndNum = ZEndNum + 1
CharAlpha = 97
End If
Next i
'Close object to avoid database bloat
myRst.Close
myDB.Close
End Sub[/vba]If I wasn't tired I'd add the capability to handle as many ending alphabets as need, e.g. C126zzzzzza but I hope 702 unique records (a --> zz) is enough.
Hope this helps!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules