Results 1 to 10 of 10
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Class Module (A2k)

    Quite busy here this week !
    I have a class module from VB6 I am trying to utilize in Access.
    The module is named cPopUpMenu.
    When the module is called as the below code, I get an error.

    "Compile Error"
    "A Module is not a valid type"

    Any Idea's

    <pre>Private Function imgRclick(i As Integer, Button As Integer)
    Dim oMenu As cPopUpMenu
    Dim lMenuChosen As Long
    If Button = vbRightButton Then
    If Me.Controls("Text" & i) = vbNullString Then Exit Function
    Set oMenu = New cPopUpMenu
    lMenuChosen = oMenu.Popup("Client Details", "-", "Supplier Details")

    Select Case lMenuChosen
    Case 1
    ' Do Something
    Case 0
    ' Do Nothing
    End Select
    End If
    End Function</pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Class Module (A2k)

    Dave,

    Can you provide some information about the class module?

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class Module (A2k)

    Edited by HansV to break long lines that caused horizontal scrolling

    Here you go :

    <pre>Option Explicit

    Private Const MF_ENABLED = &H0&
    Private Const MF_SEPARATOR = &H800&
    Private Const MF_STRING = &H0&
    Private Const TPM_RIGHTBUTTON = &H2&
    Private Const TPM_LEFTALIGN = &H0&
    Private Const TPM_NONOTIFY = &H80&
    Private Const TPM_RETURNCMD = &H100&

    Private Declare Function CreatePopupMenu Lib "user32" () As Long
    Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" _
    (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, _
    ByVal sCaption As String) As Long
    Private Declare Function TrackPopupMenu Lib "user32" _
    (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, _
    ByVal y As Long, ByVal nReserved As Long, _
    ByVal hwnd As Long, nIgnored As Long) As Long
    Private Declare Function DestroyMenu Lib "user32" _
    (ByVal hMenu As Long) As Long
    Private Declare Function GetForegroundWindow Lib "user32" () As Long

    Public Function Popup(ParamArray param()) As Long
    Dim iMenu As Long
    Dim hMenu As Long
    Dim nMenus As Long
    Dim p As PointApi

    ' get the current cursor pos in screen coordinates
    GetCursorPos p

    ' create an empty popup menu
    hMenu = CreatePopupMenu()

    ' determine # of strings in paramarray
    nMenus = 1 + UBound(param)

    ' put each string in the menu
    For iMenu = 1 To nMenus
    ' the AppendMenu function has been superseeded by the InsertMenuItem
    ' function, but it is a bit easier to use.
    If Trim$(CStr(param(iMenu - 1))) = "-" Then
    ' if the parameter is a single dash, a separator is drawn
    AppendMenu hMenu, MF_SEPARATOR, iMenu, ""
    Else
    AppendMenu hMenu, MF_STRING + MF_ENABLED, iMenu, CStr(param(iMenu - 1))
    End If
    Next iMenu

    ' show the menu at the current cursor location;
    ' the flags make the menu aligned to the right (!);
    ' enable the right button to select
    ' an item; prohibit the menu from sending messages
    ' and make it return the index of
    ' the selected item.
    ' the TrackPopupMenu function returns when the user
    ' selected a menu item or cancelled
    ' the window handle used here may be any window handle
    ' from your application
    ' the return value is the (1-based) index of the menu
    ' item or 0 in case of cancelling
    iMenu = TrackPopupMenu(hMenu, TPM_RIGHTBUTTON + TPM_LEFTALIGN + _
    TPM_NONOTIFY + TPM_RETURNCMD, p.x, p.y, 0, GetForegroundWindow(), 0)

    ' release and destroy the menu (for sanity)
    DestroyMenu hMenu

    ' return the selected menu item's index
    Popup = iMenu
    End Function</pre>


  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Class Module (A2k)

    From the error I would suspect you have pasted the code into a standard module, not a class module. Could that be the case? If so, you can't refer to it as an object. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Class Module (A2k)

    POINTAPI and GetCursorPos have not been defined, at least not in the code you posted.

  6. #6
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class Module (A2k)

    Charlotte, Yes exactly. I didn't realise there was an option to "Insert" class from the menu.

    I also changed from "Button = vbRightButton" to "Button = 2" this now works.
    I found the declaration for POINTAPI which I've created a standard module for "modUtils".

    Just one more thing, the right click menyu works but the Access menu also shows afterwards.
    Can this default menu be prevented ?

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Class Module (A2k)

    Access has a constant acRightButton with value 2.

    You can turn off the built-in right-click menus in Tools | Startup...: clear the check box labeled "Allow default shortcut menus".

  8. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class Module (A2k)

    Hans

    Can the menu be turned off in code ?
    If not, I will adjust each machine accordingly.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Class Module (A2k)

    The "Allow default shortcut menus" option is a database-level setting, not an application-level setting. It is stored with the database, so you shouldn't have to adjust other PCs.

  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class Module (A2k)

    Ok

    The very best wishes and thanks to Charlotte and your good self.
    Problem sorted.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •