Results 1 to 3 of 3
  1. #1
    WAstarita is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2011
    Location
    consult-wa.com
    Posts
    5

    Open Form by Variable

    I want to create a generic class that will

    1 .make the calling form semi transparent
    2. popup a custom window as modal
    3. return information back to the parent window
    4. open the window at the mouse cursor
    5. be independent of the calling window or window being called.

    I have 1 -4 down cold, its 5 thats the issue. Lets say I have 5 popup windows create
    pop1, pop2, pop3, etc..

    I want the calling function to look like

    Public Function OpenPopup(formName as String)



    Dim newForm as Form

    set newForm = New <formName> ' here is the issue, how do I make the form type variable so I can get an instance of the form I want without hardcoding?

    End Function

    Thanks in advance!

  2. #2
    pdebaets is offline Competent Performer
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Los Angeles
    Posts
    235
    It isn't possible to do, as far as I know.

  3. #3
    ChrisO is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2005
    Location
    Brisbane, Australia
    Posts
    27
    It is possible if we don’t try to do it.

    We can instantiate a popup container Form which holds a subform.
    The subform is automatically instantiated for us.

    Once the container Form is instantiated its SourceObject can be changed to the passed argument Form name.

    When that is done we can set the calling passback Control pointer.
    We can then position the container Form instance.
    And then we can fade in the instance of the container Form which fades its subform as well.

    Code:
    '********************************************************************************
    '*                                                                              *
    '*               Please leave any trademarks or credits in place.               *
    '*                        ChrisO, Access World Forums                           *
    '*                  http://www.access-programmers.co.uk/forums/                 *
    '*                                                                              *
    '********************************************************************************
    
    Option Explicit
    Option Compare Text
    
    ' KPD-Team 2000
    ' URL: http://www.allapi.net/
    ' E-Mail: KPDTeam@Allapi.net
    ' But somewhat modified by ChrisO.
    
    Public frmCurrentPopupForm     As Access.Form
    Public Const conSaturation     As Byte = 190
    
    Private Const LWA_ALPHA        As Long = 2
    Private Const GWL_EXSTYLE      As Long = -20
    Private Const WS_EX_LAYERED    As Long = 524288
    Private Const conOpacityStep   As Byte = 5
    Private Const conFadeSleep     As Long = 10
    Private Const conTwipsPerPixel As Long = 15
    
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
    
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    
    Private Declare Function GetWindowLong Lib "user32" _
                      Alias "GetWindowLongA" (ByVal hWnd As Long, _
                                              ByVal nIndex As Long) As Long
                                              
    Private Declare Function SetWindowLong Lib "user32" _
                      Alias "SetWindowLongA" (ByVal hWnd As Long, _
                                              ByVal nIndex As Long, _
                                              ByVal dwNewLong As Long) As Long
                                              
    Private Declare Function SetWindowOpacity Lib "user32" _
                      Alias "SetLayeredWindowAttributes" (ByVal hWnd As Long, _
                                                          ByVal crKey As Long, _
                                                          ByVal bAlpha As Byte, _
                                                          ByVal dwFlags As Long) As Long
    '
    
    
    Public Function OpenPopup(ByRef Ctl As Access.Control, _
                              ByVal strPopupFormName As String)
                         
        ' ChrisO
        Dim MouseXY As POINTAPI
            
        Set frmCurrentPopupForm = New Form_frmPopupContainer
        
        With frmCurrentPopupForm
           .ctlPopupForm.SourceObject = strPopupFormName
           .Visible = True
           
           Set .ctlPopupForm.Form.CallerControl = Ctl
           
           GetCursorPos MouseXY
           DoCmd.MoveSize MouseXY.X * conTwipsPerPixel, MouseXY.Y * conTwipsPerPixel
        
           FadeForm .hWnd, 0
           FadeInOut .hWnd, conSaturation, "In"
        End With
     
    End Function
    
    
    Public Sub FadeInOut(ByVal lhWnd As Long, _
                         ByVal bytSaturation As Byte, _
                         ByVal strInOut As String)
                         
        ' ChrisO
        Dim lngOpacity As Long
        
        Select Case strInOut
            Case "In"
                For lngOpacity = 0 To bytSaturation Step conOpacityStep
                    FadeForm lhWnd, lngOpacity
                    Sleep conFadeSleep
                    DoEvents
                Next lngOpacity
            
            Case "Out"
                For lngOpacity = bytSaturation To 0 Step -conOpacityStep
                    FadeForm lhWnd, lngOpacity
                    Sleep conFadeSleep
                    DoEvents
                Next lngOpacity
            
        End Select
    
    End Sub
    
    
    Public Sub FadeForm(ByRef lhWnd As Long, _
                        ByVal bytOpacity As Byte)
        ' KPD-Team 2000
        ' URL: http://www.allapi.net/
        ' E-Mail: KPDTeam@Allapi.net
        ' But somewhat modified by ChrisO.
        Dim lngReturn As Long
        
        ' Set the window style to 'Layered'
        lngReturn = GetWindowLong(lhWnd, GWL_EXSTYLE)
        lngReturn = lngReturn Or WS_EX_LAYERED
        SetWindowLong lhWnd, GWL_EXSTYLE, lngReturn
        
        ' Set the opacity of the layered window.
        SetWindowOpacity lhWnd, 0, bytOpacity, LWA_ALPHA
        
    End Sub

    A2003 demo attached.

    Chris.

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

Similar Threads

  1. Replies: 4
    Last Post: 04-20-2013, 10:12 AM
  2. Replies: 0
    Last Post: 08-10-2011, 11:59 AM
  3. open recordset with variable SQL
    By rivereridanus in forum Queries
    Replies: 4
    Last Post: 07-27-2011, 12:58 PM
  4. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 PM
  5. Replies: 2
    Last Post: 02-26-2010, 08:14 AM

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