Greetings,
I was working on a function today and after having got it to work, thought I'd share it with tek-tips. This function will create a table that will show ASCII codes and their respective characters.
~Melagan
______
"It's never too late to become what you might have been.
I was working on a function today and after having got it to work, thought I'd share it with tek-tips. This function will create a table that will show ASCII codes and their respective characters.
Code:
Public Function CreateASCIITable()
Dim i As Integer
Dim rst As Recordset
Dim dbs As Database
Dim strASCII As String
Dim intMsgRtn As Integer
Set dbs = CurrentDb
On Error Resume Next 'Trap error if table doesn't exist
Set rst = dbs.OpenRecordset("tblASCII")
Select Case Err
Case 0
On Error GoTo 0
intMsgRtn = MsgBox("tblASCII already exists. " _
& "Do you want to delete and rebuild all rows?", 52)
If intMsgRtn = 6 Then
dbs.Execute "DELETE * FROM tblASCII", dbFailOnError
Else
rst.Close
Exit Function
End If
Case 3011, 3078 'Couldn't find table, so build it.
Set myASCIItbl = dbs.CreateTableDef("tblASCII")
Set fldMyASCIIField = myASCIItbl.CreateField("ASCII", dbLong)
Set fldMyChrField = myASCIItbl.CreateField("Character", dbText)
myASCIItbl.Fields.Append fldMyASCIIField
myASCIItbl.Fields.Append fldMyChrField
dbs.TableDefs.Append myASCIItbl
Set rst = dbs.OpenRecordset("tblASCII")
Case Else
MsgBox "Unknown error in CreateASCIITable", vbCritical
End Select
For i = 32 To 126
strASCII = Chr(i)
With rst
.AddNew
!ASCII = i
!Character = strASCII
.Update
End With
Next
DoCmd.SelectObject acTable, "tblASCII", True
End Function
~Melagan
______
"It's never too late to become what you might have been.