Results 1 to 10 of 10
  1. #1
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295

    understanding Enums

    Good Day All,

    I am having some difficulty understanding how the values of the Enums are used. I do understanding how to create them; I see how they are used and understand that to an extent; but here is an example of what I am seeing in the Access sample NorthWind Database.

    Code:
    Private Sub cmdCompleteOrder_Click()
        If Me![Status ID] <> Shipped_CustomerOrder Then
            MsgBoxOKOnly OrderMustBeShippedToClose
            -----
            -----     
        End If
    End Sub
    The line " MsgBoxOKOnly OrderMustBeShippedToClose" Ultimately takes me to this code:

    Code:
    Sub MsgBoxOKOnly(StringID As StringIDEnum, Optional ByVal strInsert As String)
        MsgBoxID StringID, vbOKOnly, strInsert
    End Sub
    
    Function MsgBoxID(StringID As StringIDEnum, Buttons As VbMsgBoxStyle, Optional ByVal strInsert As String) As VbMsgBoxResult
        MsgBoxID = MsgBox(InsertString(StringID, strInsert), Buttons, LoadString(AppTitle))
    End Function
    Here is the Enum declaration:



    Code:
    Public Enum StringIDEnum
       
         OrderMustBeShippedToClose = 109
         PaymentInfoNotComplete = 110
         ErrorAttemptingToRestock = 111
         
    End Enum
    Now here is my problem: when this sub is activated a message box is displayed with a message " this order must be shipped to close". Of course this message is not the exact string in the Enum list of constants.
    I have search the project thoroughly and cannot find the exact message anywhere.

    Can anyone tell me where this string came from or where it is hiding; also why is the string stated in the Enum not displayed? I expected to see 109 or "OrderMustBeShippedToClose"

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you are missing the code for another function - insertstring

  3. #3
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    Thanks for your response.

    Here is the missing function:
    Code:
    Function InsertString(StringID As StringIDEnum, strInsert As String) As String
        InsertString = Replace(LoadString(StringID), "|", strInsert)
    End Function

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    which in turn has another function - loadstring

  5. #5
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    you are correct. Here are others:
    Code:
    Function LoadString(StringID As StringIDEnum) As String
        LoadString = DLookupStringWrapper("[String Data]", "Strings", "[String ID]=" & StringID)
        
        ' Verify that the specified string was found using DLookupStringWrapper.
        ' If you hit this breakpoint, verify that the StringID exists in the Strings table.
        Debug.Assert LoadString <> ""
    End Function
    Code:
    Public Function DLookupStringWrapper(Expr As String, Domain As String, Optional Criteria As String, Optional ValueIfNull As String = "") As String
        DLookupStringWrapper = Nz(DLookupWrapper(Expr, Domain, Criteria), ValueIfNull)
    End Function
    Code:
    Public Function DLookupWrapper(Expr As String, Domain As String, Optional Criteria As String) As Variant
        DLookupWrapper = DomainFunctionWrapper(DLookup_Wrapper, Expr, Domain, Criteria)
    End Function
    Code:
    Option Compare Database
    Option Explicit
    Private Enum DomainFunctionWrapperEnum
        DLookup_Wrapper
        DCount_Wrapper
        DSum_Wrapper
        DMax_Wrapper
        DMin_Wrapper
        DAvg_Wrapper
    End Enum
    Hope all are included now.

  6. #6
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    Code:
    Private Function DomainFunctionWrapper(DomainFunction As DomainFunctionWrapperEnum, _
                                        Expr As String, _
                                        Domain As String, _
                                        Optional Criteria As String) As Variant
        On Error GoTo ErrorHandler
        
        Select Case DomainFunction
        Case DLookup_Wrapper
            DomainFunctionWrapper = DLookup(Expr, Domain, Criteria)
        Case DCount_Wrapper
            DomainFunctionWrapper = DCount(Expr, Domain, Criteria)
        Case DSum_Wrapper
            DomainFunctionWrapper = DSum(Expr, Domain, Criteria)
        Case DMax_Wrapper
            DomainFunctionWrapper = DMax(Expr, Domain, Criteria)
        Case DMin_Wrapper
            DomainFunctionWrapper = DMin(Expr, Domain, Criteria)
        Case DSum_Wrapper
            DomainFunctionWrapper = DSum(Expr, Domain, Criteria)
        Case DAvg_Wrapper
            DomainFunctionWrapper = DAvg(Expr, Domain, Criteria)
        Case Else
            ' Unexpected DomainFunction argument
            Debug.Assert False
        End Select
    Done:
        Exit Function
    ErrorHandler:
        Debug.Print Err.Number & " - " & Err.Description
        
        ' Resume statement will be hit when debugging
        If eh.LogError("DomainFunctionWrapper", _
                       "DomainFunction = " & DomainFunction, _
                       "Expr = " & Expr, _
                       "Domain = " & Domain, _
                       "Criteria = '" & Criteria & "'") Then Resume
    End Function

  7. #7
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Can anyone tell me where this string came from or where it is hiding;
    it's hiding in there somewhere

    this is the function that displays the message

    Function MsgBoxID(StringID As StringIDEnum, Buttons As VbMsgBoxStyle, Optional ByVal strInsert As String) As VbMsgBoxResult
    MsgBoxID = MsgBox(InsertString(StringID, strInsert), Buttons, LoadString(AppTitle))
    End Function
    and looks like your message is stored in a table

    Suggest put a breakpoint on the code line and then step through, checking each variable as it is created/returned

  8. #8
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Do you have a table named "Strings", with fields named "String Data" and "String ID"?
    Is there a record where "[String ID]" = 109? If yes, what is the value for "String Data"?

  9. #9
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    Ok VIP; that's perfect. There is a table named "Strings", with fields named "String Data" and "String ID"? And there a record where "[String ID]" = 109.

    I am covered?

    Thanks

  10. #10
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not sure. What do you mean "covered"?

    Based on Ajax's answer, I traced through the code and found the reference to the table "Strings".

    You didn't say what the value is in the field "String Data" where "[String ID]" = 109.


    Basically, using Enums makes it easier to read the code. Which is easier to understand:
    Code:
    Private Sub cmdCompleteOrder_Click()
        If Me![Status ID] <> Shipped_CustomerOrder Then
            MsgBoxOKOnly OrderMustBeShippedToClose
            -----
            -----     
        End If
    End Sub
    or
    Code:
    Private Sub cmdCompleteOrder_Click()
        If Me![Status ID] <> Shipped_CustomerOrder Then
            MsgBoxOKOnly 109
            -----
            -----     
        End If
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Am I understanding many to many?
    By dniezby in forum Database Design
    Replies: 10
    Last Post: 04-12-2017, 06:21 PM
  2. Understanding a query in VBA
    By George in forum Access
    Replies: 11
    Last Post: 05-15-2016, 10:39 PM
  3. Need help understanding capabilities
    By squall in forum Database Design
    Replies: 2
    Last Post: 08-27-2012, 04:28 PM
  4. Understanding relationships
    By Skywalk669 in forum Database Design
    Replies: 4
    Last Post: 05-01-2012, 03:08 PM
  5. Understanding SQL Querys
    By jacobbiljo in forum Access
    Replies: 8
    Last Post: 11-17-2009, 05:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums