Public Prodecure & Enum

When I use the insertlog prod. it puts the Number of the Enum ex. LoggedIn = 0 so it saves the Log Type as 0 and not LoggedIn. How can I fix this so it will put logged in and not 0?

Public Enum LogTypes
    LoggedIn
    LoggedOut
    ClientError
    ServerError
    SignOff
    EmployeeControl
    HR_Employees
    Password_Changed
    Other
    Delete_Que
    Customer
    Vendor
    CreatedNewHazMat
    'Add New Logtypes in the frmLog_Delete form
End Enum

Public Function InsertLog(eLogTypes As LogTypes, strDescription As String, Optional bInsertInStatusBar As Boolean)
On Error Resume Next
On Error GoTo errHandler
Dim reRS As MYSQL_RS
Dim reConn As MYSQL_CONNECTION
Set reRS = New MYSQL_RS
Set reConn = New MYSQL_CONNECTION

    If PingServer = True Then
          reConn.OpenConnection strSvrAddress, strMySQLUsername, strMySQLPassword, strSvrSchema, strSvrPort
          reRS.OpenRs "SELECT * FROM log_database", reConn
    Else
        RBox ServerNotFound_Ping
    End If

    reRS.AddNew
        reRS.Fields("LogType") = eLogTypes
        reRS.Fields("EmployeeID") = CurrentUser.UserInfo_EmployeeID
        reRS.Fields("EmployeeName") = CurrentUser.UserInfo_FullName
        reRS.Fields("Date") = Format(Date, "mmm. dd/yyyy")
        reRS.Fields("Time") = Format(Time, "hh:mm:ss")
        reRS.Fields("Description") = strDescription
    reRS.Update
   
    If bInsertInStatusBar = True Then
        Status strDescription
    End If
   
    reRS.CloseRecordset
    reConn.CloseConnection
    Set reRS = Nothing
    Set reConn = Nothing

errHandler:
    If Err.Number <> 0 Then
    EBox Err.Number, Err.Description, Sql, "SQLGetData #" & Erl, "MySQL_Mod.", "GetData"
    End If
End Function
thaburnerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Data DudeCommented:
I'm really not sure if this helps you, but with a function you have to define it AS a variable, then you can set it to whatever in your code...

Public Function InsertLog(eLogTypes As LogTypes, strDescription As String, Optional bInsertInStatusBar As Boolean) As Boolean

'Your Code

'If something then
  InsertLog = True
'else
  InsertLog = False
'End If

End Function
Jim HornMicrosoft SQL Server Data DudeCommented:
This may be it as well...

        reRS.Fields("LogType") = eLogTypes.LoggedIn  'Added .LoggedIn
jmundsackCommented:
It sounds like you want to access the textual name of the enum member, and I'm afraid you cannot do this.  You would need to supply a translation function that returns the textual name in place of the enum value (which is internally just a Long Integer).  Something like:

Private Function GetEnumMemberName(ByVal Value As LogTypes) As String
    Dim strResult As String
    Select Case Value
        Case LoggedIn: strResult = "LoggedIn"
        ' etc...
        Case Else: Err.Raise 9
    End Select
    GetEnumMemberName = strResult
End Function

This is quite tedious, I know, but if I read your question correctly it's the only way.  You might consider doing something with a collection.  At the start of the program fill up a collection with the textual names in the exact order of the enum values.  Like so:

(global declarations)
Global gEnumMemberNames As Collection

(program startup)
    Set gEnumMemberNames = New Collection
    gEnumMemberNames.Add "LoggedIn"
    ' etc.

(anywhere in code)
    Debug.Print gEnumMemberNames(LoggedIn - 1)
    ' note: need the -1 because the enum base is 0, but the collection base is 1

Alternatively, you could set the enum base to 1 by specifying it explicitly on the first member of the enum:

Public Enum LogTypes
    LoggedIn = 1
    LoggedOut     ' the rest will be incrementally above 1
    ClientError
    ServerError
    ' etc.
End Enum

Then you could access the collection items without the -1, like so:

(anywhere in code)
    Debug.Print gEnumMemberNames(LoggedIn)

HTH -Jon

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EDDYKTCommented:
when vb compiles, it will change all string to number. No way you can retrieve the string after compiled to exe format
thaburnerAuthor Commented:
jmundsack i used your GetEnumMemberName Function that worked perfect ya it is a little tideous but it does the trick.
Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.