Form design in VBA window but not in navigation pane

Insane_ai

Not Really an A.I.
Local time
Today, 14:31
Joined
Mar 20, 2009
Messages
262
I inherited this and need to understand it. Can someone point me to a reference that explains what is being done here and why this method would be preferable over the normal object designer?

I understand this creates a calender object. I don't understand being able to view the form design in the vba window but not in the navigation pane. Also, when I right click to switch between View Code and View Object on a normally created form, I am sent back to the database window / navigation pane.

Code below, screenshot attached.




Code:
Option Compare Database
Option Explicit

Private WithEvents Calendar1 As clsCalendar

Public Target As Date

Private Sub UserForm_Initialize()
    If Calendar1 Is Nothing Then
        Set Calendar1 = New clsCalendar
        With Calendar1
            .Add_Calendar_into_Frame Me.Frame1
            .UseDefaultBackColors = False
            .DayLength = 3
            .MonthLength = mlENShort
            .Height = 140
            .Width = 180
            .GridFont.Size = 7
            .DayFont.Size = 7
            .Refresh
        End With
        Me.Height = 173 'Win7 Aero
        Me.Width = 197
    End If
End Sub

Private Sub UserForm_Activate()
    If IsDate(Target) Then
        Calendar1.Value = Target
    End If
End Sub

Private Sub Calendar1_Click()
    Call CloseDatePicker(True)
End Sub

Private Sub Calendar1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = vbKeyEscape Then
        Call CloseDatePicker(False)
    End If
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
        Cancel = 1
        CloseDatePicker (False)
    End If
End Sub

Sub CloseDatePicker(Save As Boolean)
    If Save And IsDate(Calendar1.Value) Then
        Target = Calendar1.Value
    End If
    Me.Hide
End Sub
 

Attachments

  • Question1.png
    Question1.png
    13.5 KB · Views: 281
It looks like it creates a datepicker control, instead of using the inbuilt one.

If this is an old 2003 mdb or earlier, then the inbuilt datepicker didn't exist, hence some people "rolled their own".
 
It looks like it creates a datepicker control, instead of using the inbuilt one.

If this is an old 2003 mdb or earlier, then the inbuilt datepicker didn't exist, hence some people "rolled their own".

This is for an access 2000 application that I am working to upgrade to V2016.


Can you explain why it would be designed this way and yet not available in the database window? I've never seen this approach before.
 
They are not using an Access form to do this, but an MSForms. Same as you do in Excel. It is a little tricky in the VBA window to find how to add a user form to your project. I think it is in the vba settings. I do this also for my calendar controls, because you can make it function more like a control. The MSFORMS have similar controls to Access, but some have slightly different properties. You can add most of these controls to your forms as well. They include some controls not in Access such as spinners. Doing it this way is often very portable.
 
Also Access use to have a native calendar control you can add to the form, but they did away with it. Instead you have the popup that can be present on any date field with the little icon next to the field, but this is not the same a a visible Calendar.
 
I believe these are the steps to allow you to add an MSFORMs userform to access in vbe.
In the Access Visual Basic
Editor, if you right-click on the toobar, select 'Customize', 'Commands' and
'Insert', you will find a button for... adding UserForms!
 
Thank you again, I found exactly what you expected...screenshot attached.
 

Attachments

  • Form.png
    Form.png
    10.2 KB · Views: 273

Users who are viewing this thread

Back
Top Bottom