[AccessD] ...close open forms

William Hindman wdhindman at bellsouth.net
Wed Jan 18 12:01:18 CST 2006


----- Original Message ----- 
From: "William Hindman" <wdhindman at bellsouth.net>
To: "Access Developers discussion and problem solving" 
<accessd at databaseadvisors.com>
Sent: Wednesday, January 18, 2006 12:58 PM
Subject: Re: [AccessD] ...close open forms


> Shamil
>
> ...I use both now ...I generally prefer bound forms ...but in apps with 
> several users I've run into problems with record locking ...so for those 
> forms where this is happening I've gradually been converting to unbound 
> forms.
>
> ...but what I'm looking for here is a generic plug-in that will work 
> equally well with both ...I'm building a new user interface that uses a 
> treeview switchboard form that is always in view ...one of the problems 
> being of course that a user can select from the switchboard at any time 
> even when a form is already open ...there are a number of ways to cover 
> that but what I was hoping someone had was a function that I could simply 
> call on form open that would iterate through all open forms, except those 
> I want left open, saving any dirty data, and closing them before opening 
> the new form.
>
> ...I'll try the approaches you and Gustav have posted and let you know 
> ...thanks for the quick replies :)
>
> William
>
> ----- Original Message ----- 
> From: "Shamil Salakhetdinov" <shamil at users.mns.ru>
> To: "Access Developers discussion and problem solving" 
> <accessd at databaseadvisors.com>
> Sent: Wednesday, January 18, 2006 9:53 AM
> Subject: Re: [AccessD] ...close open forms
>
>
>> William,
>>
>> It's unclear what do you mean by saving data before closing form - do you
>> have unbound forms?
>>
>> For bound forms this code should work well:
>>
>> Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" 
>> ( _
>>    ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
>>    lParam As Any) As Long
>> Private Const WM_CLOSE = &H10
>>
>> Public Sub CloseForms( _
>>   ByRef robjApp As Access.Application, _
>>   Optional ByRef rcolFormNames2Skip As Collection = Nothing)
>> Dim lngIdx As Long
>> Dim efrm As Access.Form
>>    With robjApp.Forms
>>        If .Count > 0 Then
>>            For lngIdx = .Count - 1 To 0 Step -1
>>               Set efrm = .Item(lngIdx)
>>               If Not SkipThisForm(rcolFormNames2Skip, efrm) Then
>>                  ' force to save data in bound form before
>>                  '  closing it
>>                  efrm.SetFocus
>>                  DoEvents
>>                  SendKeys "+{Enter}", True
>>                  ' close form
>>                  SendMessage efrm.hWnd, WM_CLOSE, 0, 0
>>                  DoEvents
>>               End If
>>            Next lngIdx
>>        End If
>>    End With
>> End Sub
>>
>> Private Function SkipThisForm( _
>>         ByRef rcolFormNames2Skip As Collection, _
>>         ByRef rfrm As Access.Form) As Boolean
>> Dim evar As Variant
>>    If Not rcolFormNames2Skip Is Nothing Then
>>       For Each evar In rcolFormNames2Skip
>>          If StrComp(CStr(evar), rfrm.Name, vbTextCompare) = 0 Then
>>             SkipThisForm = True
>>             Exit Function
>>          End If
>>       Next evar
>>    End If
>>    SkipThisForm = False
>> End Function
>>
>> It can be called this way from Switchboard form:
>>
>> Dim col As New Collection
>>    col.Add Me.Name
>>    CloseForms Access.Application, col
>>
>>
>> You can also implement a special predefined public method in all your 
>> forms,
>> which can be called to save data before closing the form etc....
>>
>> Shamil
>>
>> ----- Original Message ----- 
>> From: "William Hindman" <wdhindman at bellsouth.net>
>> To: "Access Developers discussion and problem solving"
>> <accessd at databaseadvisors.com>
>> Sent: Wednesday, January 18, 2006 5:01 PM
>> Subject: [AccessD] ...close open forms
>>
>>
>>> ...I need to close any open forms ...other than designated forms ...and
>> save
>>> their data ...before opening a called form ...from the called form.
>>>
>>> ...ie call a form open from a switchboard ...the called form checks for
>> any
>>> other forms open, other than the sb, and closes them, saving their data,
>>> before it opens.
>>>
>>> William
>>>
>>>
>>> -- 
>>> AccessD mailing list
>>> AccessD at databaseadvisors.com
>>> http://databaseadvisors.com/mailman/listinfo/accessd
>>> Website: http://www.databaseadvisors.com
>>
>> -- 
>> AccessD mailing list
>> AccessD at databaseadvisors.com
>> http://databaseadvisors.com/mailman/listinfo/accessd
>> Website: http://www.databaseadvisors.com
>>
> 





More information about the AccessD mailing list