Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flicker free form resizing of a sizable Access form 1

Status
Not open for further replies.

patriciaxxx

Programmer
Jan 30, 2012
277
GB
I need flicker free form resizing of a sizable Access form, when there is a minimum size limit controlled by the form's Resize event, and the user tries to change the size.

The following code (which I did not write and do not fully understand) does accomplish this, however looking at it I believe it is intended for a msform (UserForm) not an Access form.

So can anybody modify the code so that it works with an Access form?

Code:
[COLOR=#204A87]Private Const MyFormWd As Long = 5000
Private Const MyFormHt As Long = 6000

'********************
' Form_Resize
' Resize the form
'********************
Private Sub Form_Resize()
  Select Case Me.WindowState
    Case vbMinimized
      Exit Sub
    Case vbNormal
      'if too small...
      If Me.Width < MyFormWd _
         Or Me.Height < MyFormHt Then
        With Me.tmrResize 'smooth w/timer
          .Enabled = False 'turn timer off
          DoEvents 'screen catch up
          .Enabled = True 'restart timer
        End With
        Exit Sub 'let timer do work
      End If
  End Select
  '
  'other control arrangement code goes here.
  '
End Sub

'********************
' tmrResize_Timer
' Check Win for too small
'********************
Private Sub tmrResize_Timer()
  '
  'turn off timer
  '
  Me.tmrResize.Enabled = False
  '
  'do nothing if minimized
  '
  If Me.WindowState = vbMinimized Then
    Exit Sub
  End If
  '
  'resize to minimum dims
  '
  If Me.Width < MyFormWd Then
    Me.Width = MyFormWd
  End If
  If Me.Height < MyFormHt Then
    Me.Height = MyFormHt
  End If
End Sub
[/color]
 
I believe it is intended for a msform
Why are you believing that ?
 
Hello PHV

Well it doesn’t compile in my access database. It fails on Me.WindowState, it fails on vbMinimized, infact it fails on a whole load of things. My vba skills are not very good yet but I haven’t seen these property’s in Access before. Also it originally came from a vb site I think.

The thing is it solves the flickering issue on whatever form it was written for and I was hoping someone might know enough about whatever code it is written in and vba to make it solve the flickering issue in an Access form, which is what I’m trying to do.
 
The thing is it solves the flickering issue
How can a code that doesn't compile solve anything ?
 
Hello PVH

I didn’t say it solves the flickering issue.

I said it solves the flickering issue on whatever form it was written for, and asked if someone could modify it to work for an Access form.

Anyway I don’t see how this is helping.

Do you understand the code?

Are you saying the code should work for an Access form?

Do you have a code solution that does work for an Access form?

 
>My vba skills are not very good yet

They really ought to be improving by now, though. Seriously.

>Do you have a code solution that does work for an Access form?


I do ... but it involves creating a small ActiveX DLL in VB6 in order to subclass the Access form (you can't subclass properly directly in Access; the IDE cauues problems). So, if you haven't got VB6 it won't be of any use.
 
Hello strongm

I have seen Access modules written which exposes a function that creates an in-memory, COM-compatible object that is written in native VB6 code rather than VBA. This then all works from Access.

Would you be able to modify the solution you have along these lines so that I can use it.

By the way I think my vba skills are improving its when we throw other languages in the mix it all gets too complicated.

Your help is much appreciated, thank you.

 
>I have seen Access modules written which exposes a function that creates an in-memory, COM-compatible object

One suspects you've seent the mouse scroll wheel code. This is NOT native VB6. It is a native machine code solution, that uses VBA to dynamically create a valid COM-compatible object created in memory from the machine code.

I do not have such a solution for controlling the window size, nor do I have the time to knock one together for you, I'm afraid.
 
What I can do - and normally don't - is provide you with my DLL ...


Once you've got it, then it can be used more-or-less this simply:

Option Compare Database
Option Explicit

Private MinMax As New cLimitSize

Private Sub Form_Open(Cancel As Integer)
MinMax.minX = 400 ' pixels
MinMax.minY = 600 ' pixels
MinMax.SubClassHookWindow Me.hWnd
End Sub

Private Sub Form_Close()
MinMax.SubClassUnHookWindow
End Sub
 
Hello strongm

That is really very good of you, thank you very much.

Where do I get your dll from?
 
You'll need to register the dll, since it is not provided with an installation program:

The windows program named c:\windows\regsvr32.exe is used to register and unregister ActiveX DLL's and OCX's. You RUN regsvr32 as follows:

[tt] Register: regsvr32 dllFileName.dll
UnRegister: regsvr32 /u dllFileName.dll[/tt]

The above example assumes that the target "dllFileName.dll" is in your computer's path. (Regsvr32 is also assumed in the path.)

And then, as with any com library you need to set a reference to it. It is called clsMinMax
 
Thank you strongm

I will give it a go and let you know how I got on.



 
Hello strongm

I got it all working just as you said.
And it certainly solves the flicker problem, it works like a charm.
Thank you for your time responding to this thread and for your generosity it providing your dll and such a professional solution.
Much appreciated.
 
Hello strongm

Is it possible to use the LoadLibrary functions with the MinMax dll?

I tried the following code but when I open the form I get error 429 ActiveX component can’t create object?

Code:
[COLOR=#204A87]Option Compare Database
Option Explicit

Private Declare Function LoadLibrary Lib "kernel32" _
Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long

Private Declare Function FreeLibrary Lib "kernel32" _
(ByVal hLibModule As Long) As Long

Private hLibMinMax As Long

Public Function testLoadMinMaxDll() As Boolean
Dim blRet As Boolean
blRet = LoadLib()
If blRet = False Then
    Exit Function
End If

If hLibMinMax <> 0 Then
    hLibMinMax = FreeLibrary(hLibMinMax)
End If

End Function

Private Function LoadLib() As Boolean
Dim s As String
Dim blRet As Boolean

On Error Resume Next

LoadLib = False

If hLibMinMax <> 0 Then
    hLibMinMax = FreeLibrary(hLibMinMax)
End If

s = "Sorry...cannot find the clsMinMax.dll file" & vbCrLf
s = s & "Please copy the clsMinMax.dll file into the same folder as this Access MDB or your Windows System32 folder."

hLibMinMax = LoadLibrary(CurrentDBDir() & "clsMinMax.dll")
    
If hLibMinMax = 0 Then
    hLibMinMax = LoadLibrary("clsMinMax.dll")
End If

If hLibMinMax = 0 Then
    MsgBox s, vbOKOnly, "MISSING clsMinMax.dll FILE"
    LoadLib = False
    Exit Function
End If

LoadLib = True
End Function

Private Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
    strDBPath = CurrentDb.Name
    strDBFile = Dir(strDBPath)
    CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function

[/color]
 
Before I answer this, can you explain to me how you move from "I'm still learning VBA" to LoadLibrary?
 
Hello strongm

I’m sorry but I don’t know what you mean.

I have used LoadLibrary in other Access dbs with other dlls and thought it might be possible here, I guess what your saying is its not possible with your dll?
 
OK, let me ask a different question: what do you think LoadLibrary does?
 
Hello strongm

I thought it loaded library files like dlls or other executable files.

Like I said I have used it in other Access dbs with dlls, I’m still guessing not yours though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top