AL: Basics of Classes in VBA with Adrian Bell

AccessUserGroups.org
AccessUserGroups.org
1 هزار بار بازدید - 7 ماه پیش - Why use a class instead
Why use a class instead of a standard module for some of your VBA code? When you’ve seen the sorts of things you can do, and how easy it can be, you’ll answer that for yourselves. VBA Class Basics with Adrian Bell for Access Lunchtime.

Adrian said, "With a simple template AccDB file, I will show some of the very basics of using classes within VBA". What the classes do is less the point than providing, and to a certain extent explaining, the bare bones of their use and how some of the basic approaches are managed. Hopefully a starting point for any interested in taking class work further.

download:
https://accessusergroups.org/lunch/ne...

00:00 before meeting for Adrian's Basics of Classes in VBA
smile, frost blossom, raise hand
Maria, lower hands, mine's getting tired
1:51 Introduce Adrian Bell by Maria Barnes for Basics of Classes in VBA
admin for Bytes.com, posts as NeoPa
3:00 Adrian, Basics of Classes in VBA
3:17 Why Use Classes?
reasons vary
powerful tools
go into basics
needn't expect to see anything overly-complicated
apply constency
mainly for illustration of concepts
4:42 What MY database uses classes for
forms in restored view (use overlapping windows not tabbed view)
report fills up as much of the screen as possible
hide parent form after selection
reshows parent after last child has been closed
communication between objects
6:01 demo
6:08 simple menu: Menu A, Menu B, Menu C
7:35 Reports menu
report class knows when last report is closed
8:33 open 3 different reports, Ctrl+F6 = toggle
form no longer visible
when last report closed, menu form becomes visible
9:20 Property Get
11:28 Set is for objects and Let for scalars
11:45 Property Let
13:15 Property Set
15:04 Question, New
16:45 Access window
16:47 menu form
16:57 VBA code, frmMainMenu
17:15 Private WithEvents at top
17:49 event handlers use the internal name
18:06 Form_Open
20:07 choose Menu B from form
20:24 New and WithEvents
Form_Open
21:08 clsTo.frmFrom (parent)
21:36 Public Function ShowForm
Initialised
Restore
open specified form
set frmChild
22:44 strTo is the name of the form
pass extra in case there is a need
22:33 EventPrep
24:21 "[Event Procedure]" put in when you have an event handler
24:34 Ctrl+Shift+F2 Last Position
that is what happens when you open another form
25:36 close Menu B
set a trap in there so we get the code
25:04 vba frmChild_Close -- from WithEvents object
26:34 top of clsForm -- frmParent, WithEvents frmChild
27:07 breakpoint in frmChild_Close on frmParent.Visible = True
click button, gone to that
Restore
pass name back to caller
29:05 Public Event Closed in clsForm
30:07 RaiseEvent statement
clsTo_Closed event handler we looked at earlier
don't have to have it, can't say that enough times
handle them if you want to, but you don't have to
31:10 [%F] is for subtitution
31:36 end that event handler
get back to code immediately after RaiseEvent
32:12 back to where we started
34:41 report - allows multiple children objects to be opened, will handle the last one is closed
how to remember which reports are open
Fixed-length string
Initialised
EventPrep
35:26 ShowReport
code to open and handle the last one
38:34 intIdx is an index
Instr(strInUse, vbNullChar)
is there a slot available?
44:21 OpenReport
openend rpt03
Secect Case intIdx
1 and 2 set when we weren't watching
42:36 Mid Statement
43:30 what happens when reports close
strInUse: compare to String( conNumRpts, vnNullChar)
maybe other things happened
RaiseEvent AllClosed
ByRef -- take a different approach
48:57 Summarize
51:17 Ade links
51:24 Upcoming AUG presentation on Classes
The Power of Sub Classes in VBA with Kent Gorrell for Access Pacific
https://accessusergroups.org/pacific/...
date: Thursday, 4 January 2024
time: 6:30 pm Pacific
all are welcome, join us
51:48 Questions, Ctrl+F6
54:17 here to show that one can get into classes easily
55:00 Next for Access Pacific -- Kent
55:27 Maria - what other examples for classes?
Neil -- Outlook listen and save data before Send
Eric  -- model a domain item
tjacobi -- working with table
58:40 perhaps Neil will do a presentation
59:24 Question about fixed-length string
wasn't about space, like an array
1:00:23 let things run onwards

NEXT for Lunchtime
2024 Plans for Access by Maria Barnes
https://accessusergroups.org/lunch/ev...
date: Tuesday, 30 January 2024, noon Central time
join us! all who want to know and share about Access are welcome

Access Lunchtime
Last Tuesday
https://accessusergroups.org/lunch/
7 ماه پیش در تاریخ 1402/10/08 منتشر شده است.
1,060 بـار بازدید شده
... بیشتر