ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Closing Dataform automatically (https://www.excelbanter.com/excel-programming/279063-closing-dataform-automatically.html)

Dkline[_2_]

Closing Dataform automatically
 
I have a spreadsheet used as a database. Upon open or activation I want to
show the dataform automatically. Upon close or deactivation of the worksheet
I want it to close automatically.

My code on closing or deactivation doesn't work. You have to physically
select the close button on the form or use Alt-L for the keyboard shortcut.
Apparently the open form precludes the macros.

Can I close the form automatically and, if so, how?

My code (in ThisWorkbook)

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
SendKeys "%{L}", True
End Sub

Private Sub Workbook_Open()
On Error Resume Next
ActiveSheet.ShowDataForm
End Sub

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
On Error Resume Next
ActiveSheet.ShowDataForm
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
On Error Resume Next
SendKeys "%{L}", True
End Sub




Dave Peterson[_3_]

Closing Dataform automatically
 
It sure looks to me that you can't change sheets/windows until you dismiss that
Data|Form.

How about just hitting the Escape key?



Dkline wrote:

I have a spreadsheet used as a database. Upon open or activation I want to
show the dataform automatically. Upon close or deactivation of the worksheet
I want it to close automatically.

My code on closing or deactivation doesn't work. You have to physically
select the close button on the form or use Alt-L for the keyboard shortcut.
Apparently the open form precludes the macros.

Can I close the form automatically and, if so, how?

My code (in ThisWorkbook)

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
SendKeys "%{L}", True
End Sub

Private Sub Workbook_Open()
On Error Resume Next
ActiveSheet.ShowDataForm
End Sub

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
On Error Resume Next
ActiveSheet.ShowDataForm
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
On Error Resume Next
SendKeys "%{L}", True
End Sub


--

Dave Peterson



All times are GMT +1. The time now is 07:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com