Sie sind auf Seite 1von 14

MicrosoftAccess2010

Forms&Macros

Email:training@health.ufl.edu
WebPage:http://training.health.ufl.edu

MicrosoftAccess2010:Forms&Macros
1.5hours
Thisworkshoprequirescompletionof"Access:Basics","IntrotoFormsandReports",and
"Forms".Topicsincludecreatingmenus;linkingformsthroughbuttons;creatingtabular
SubForms;creatingmacros;usingmacrosinbuttonsandinotherevents.

MainMenuReview.......................................................................................................................1
StartupOptions..........................................................................................................................1
ModifyingFormProperties.............................................................................................................2
LinkingFormsReview....................................................................................................................3
TabularForm...................................................................................................................................4
InsertingaSubForm........................................................................................................................5
ModifyingaSubForm..................................................................................................................6
CreatingaMacro.............................................................................................................................7
OpenFormActionArguments....................................................................................................8
GoToRecordFormActionArguments.........................................................................................8
NoteforEarlierVersions.............................................................................................................8
CreatingaButtontoRunaMacro...................................................................................................9
UsingtheCommandButtonWizard...........................................................................................9
UsingthePropertySheet............................................................................................................9
DraggingfromtheNavigationPane............................................................................................9
ModifyingExistingButtons............................................................................................................10
MacroActions................................................................................................................................11
NonButtonMacros.......................................................................................................................12
Help...............................................................................................................................................12

PandoraRoseCowart

SeniorTrainingSpecialist
AcademicHealthCenterTraining

C3012ACommunicore
POBox100152
Gainesville,FL326100152

Updated11/28/2011

(352)2735051
prcowart@ufl.edu
http://training.health.ufl.edu


MainMenuReview
RecreatetheMainMenuformandsetittoopenwhenthedatabasestarts.Itdoesnotneedtolookjust
likethisone,butitshouldhavefiveworkingbuttons.

1. FromtheCreatetab,clickontheFormDesignbutton

2. CreateCommandButtonsbyusingthecontrolsontheDesigntab
a. Besuretogivethebuttonsuniquenames

b. EachOpenFormbuttonshouldreturnALLtherecords
c. Applicationcategory>QuitApplication

3. SaveFormas"MainMenu"

4. Testeachofthebuttonstomakesuretheyareopening
theformsyouwanted

5. (Ifyouhavetime)Formatasdesired
a. UsetheQuickStylesandChangeShapeoptions
ontheFormattab
b. UseaLabeltocreatethetitle

StartupOptions
1. OpentheFilemenu,ChooseOptionsnearthebottomofthemenu

2. ChooseCurrentDatabasefromthepaneontheleft

3. IntheApplicationOptionsChangetheDisplayFormtoMainMenu

Page1


ModifyingFormProperties

Record
Selector

NavigationButtons

Views

1. InthedesignviewopentheFormproperties

2. Turnoffextraviews
a. (allowformviewYES)
b. AllowDatasheetViewNo
c. AllowPivotTableViewNo
d. AllowPivotChartViewNo
e. AllowLayoutViewNo
f.

AllowDatasheetViewNo

3. TurnoffRecordbuttons
a. RecordsSelectorsNo
b. NavigationButtonsNo

Note:RememberyoucanDoubleclickonthedropdown
listsinthepropertiesanditwillcycletothenextvalueon
thelist.Inthesecases:YesbecomesNo.

Page2


LinkingFormsReview

TheEmployeesformhasabuttononthe
departmenttabthatopensthedepartmentforjust
thatemployee.We'lldothesameforthePatient's
form;createabuttontoopentheVisitsforjustthis
Patient.

1. OpenthePatientsform

2. CreateCommandButtonbyusingthe
controlontheDesigntab
a. FormOperation>OpenForm>
PatientVisits
b. "Opentheformandfindspecific
datatodisplay"
c. ChooseMedRecfromeachsideto
helpAccessseethelinkbetween
thetwoforms
d. Setthebuttontoshowapicture
andgiveitameaningfulname

3. Testthebutton

4. AdjustPlacementandReformat

Page3


TabularForm
TheEmployeetableiscurrentlyembeddedintheDepartmentform.WewanttomakeaTabular
SubFormtoreplaceit.

1. SelecttheEmployeetablefromtheNavigationPane

2. FromtheCreateTab,undertheMoreFormsmenu,ChooseMultipleItems

3.
4.
5.
6.

7.
8.

Turntothedesignview

DeleteallthefieldsbutFirstandLast

DeletetheEmployeestitleandFormsimage

Sizelabelsandtextboxestothe"shortest"
a. Movelabelstothetopoftheirsection

Resizetheheaderanddetailsections

OpenFormProperties(datatab)
a. AllowDeletionsNo

9. Addabuttontoopentheemployeeformforthisemployee
a. FromtheDesignTab,createaCommandbutton
b. OpenAForm,EmployeeForm,Findspecificdatatodisplay
c. LinkbyLast
d. Caption"MoreInfo"
e. Giveitameaningfulname

10. Testthebutton

11. MovethebuttontotheHeader
a. Testagain

12. Movebacktothedetail

13. SelectAll,fromtheArrangeTabchooseTabular
a. AdjustsizeofNamefieldsinLayoutView

14. CloseandSaveas"DepartmentsSubForm"
Page4


InsertingaSubForm
1. OpentheDepartmentsForminDesignview

2. DeleteEmployeestable

3. OpentheControlsmenuontheDesigntabclickonthe
SubFormbutton
a. Clickinthegridtoplaceitontheform

4. Followthestepsofthewizard
a. UseanExistingFormDepartmentsSubForm

b. Becauseourrelationshipsaresetupproperlyandwearen'tdoinganythingfancy,
AccessknowstolinkthesebyDeptID,butwecanclickontheDefinemyownoptionto
setitourselves

c. NamethecontrolDepartmentEmployees

ThesizeofthecontrolisdeterminedbythesizeofthegridoftheSubForm.Let'sgofixitandtryagain.
1. Closeanddon'tsavetheDepartmentsform

2. OpentheDepartmentsSubFormFormindesignview

3. Adjustthegridtobeunder4"wide

4. CloseandSaveDepartment'sSubForm

5. RepeatstepsatthetopofthispagetoreinserttheSubFormControlintotheDepartmentsForm
Page5

ModifyingaSubForm
1. OncetheSubFormisinplace,gototheLayoutView

2. ResizetheSubFormtofitatleast6employees

3. GototheDesignView

4. OpenthePropertySheet

5. ClickonceontheSubFormcontroltoselectit

6. Clickonitagainto'getinside'
a. Lookforthemarkinthetopleftcornerthatshowswhichformiscurrentlyselected

MainForm

SubFormControl

7. IntheFormpropertiesoftheSubFormchange
a. AllowAdditionsNo

SubForm

b. NavigationButtonsNo

8. TurntotheFormView,makesureyouturnedoffthecorrectproperties

Page6


CreatingaMacro
Buttonsarelimitedtoonlyoneactionatatime:openaform;gotothenextrecord,exittheapplication.
IfyouwantabuttontodomultipletasksyoucansetupaMacroandthenhavethebuttondothesingle
'miscellaneous'taskof:RunaMacro.

WearegoingtocreateaNewPatientbuttonandaNewEmployeebuttonforourMainMenu.Tocreate
anewrecordweneedto(1)Openaformand(2)GotoanewRecord.Wecancreatebuttonstodo
each,butnotboth.

1. FromtheCreateTab,chooseMacro

2. FromtheActionmenuchooseOpenForm

3. ChangetheFormNamepropertytobePatients
a. Leavetheotherpropertiesalone

4. Forthenextstep,chooseGoToRecordfromtheActionmenu

5. ChangetheRecordpropertytobeNew
a. Leavetheotherpropertiesalone

6. SavetheMacroas"NewPatient"

7. RuntheMacro
a. ItshouldtakeyoutoablankPatientformtoRecord77

Page7

OpenFormActionArguments
FormNameThisdropdownlistwillprovideyouwith
alistofalltheformsinyourdatabase.

ViewForm,Design,PrintPreview,Datasheet,

FilterNameNameofaQuery(spellingcounts)that
willlimityourrecords

WhereConditionAnSQLstatementsuchasSelect*fromPatientswherePatient.City="Waldo"

DataModeAdd,Edit,orReadOnly.Ifyouleavethisblank,Accesswillopentheformasit'ssaved.
AddDataEntrypropertysettoYes.ThiswillopentheformandONLYshowyouanewrecord.
EditPropertiesAllowAdditions,AllowDeletions,AllowEditsallsettoYes.
ReadOnlyPropertiesAllowAdditions,AllowDeletions,AllowEditsallsettoNo.

WindowModeNormal,Hidden,Icon,Dialog.
NormalOpensthewaythedatabaseisset(OverlappingWindowsorTabbedDocuments)
HiddenOpenstheformbuthidesitfromview.Thisisasimplewaytomakeaglobalvariable.
IconWhenyouareusingtheOverlappingWindowsthiswillminimizetheform
DialogPropertiesModal,andPopuparesettoYes.Thiswillopentheformasafloating
windowThisisgoodforsearchboxes,errormessages,andsearchwindows.

GoToRecordFormActionArguments
ObjectTypeTable,Query,Form

ObjectNameThislistwillpopulatewithoptions
basedontheselectionintheObjectType.IfObject
TypeandObjectNameareleftblank,Accessassumes
the'current'databaseobject.

RecordPrevious,Next,First,Last,GoTo,New

OffsetThisoptionisusedwhentheRecordchoiceis"GoTo".Wegotoanoffsetofi.e.+5willjump
forward5records,5willjumpback.Thisisespeciallyusefulwhenwehavedatawithmanysimilar
values.Insteadofmovingonerecordatatimewecan'Jump'viaourOffset.

NoteforEarlierVersions
IfyouareusingOffice2007orearlier,
yourmacroscreen,itwilllookmore
likethisone.
InsteadofhavingtheAction
ArgumentsundereachAction,they
appearatthebottomofthewindow.
TheActionlistandActionArguments
arethesame,butinthisnewOffice
2010versionitlooksverydifferent.
Page8


CreatingaButtontoRunaMacro

UsingtheCommandButtonWizard
1. OpentheMainMenuforminDesignView

2. FromthecontrolsintheDesigntab,createa
CommandButton

3. ChoosetheMiscellaneouscategory,Run
Macroaction

4. ChoosetheNewPatientMacro

5. ChangethetexttoNewPatient

6. Givethebuttonameaningfulname
a. Somethinglike,cmdMcrNewPatient

7. TesttheButton

8. Formatthebuttontolookliketheothers

UsingthePropertySheet
1. CopyandPastethebutton,ChangetheCaption(name)tobeNewEmployee
a. AlignitwiththeEmployeebutton

2. CreateaNewEmployeeMacro

3. NewEmployeeButtonstillopensPatientsForm

4. OpenthePropertySheetfortheNewEmployeebutton
a. ChangetheOnClickproperty(eventtab)to
NewEmployee

5. OpenthePropertySheetfortheNewPatientbutton
a. ChangetheOnClickpropertytoNewPatient

DraggingfromtheNavigationPane
1. OpenthePatientsForminDesignView

2. DragtheNewPatientmacroontotheform

3. Adjustformatandplacement

4. OpenthePatientVisitsForminDesignView

5. DragtheNewPatientmacroontotheform

6. AdjustFormatandPlacement
Page9


ModifyingExistingButtons
InAccess2003orearlierbuttonswerebasedonVBA,VisualBasicforApplicationscode.Ifweneededto
editabuttonwehadtowadethroughscreenssuchasthis:

BeginninginOffice2007,newbuttonsarecreatedwithEmbeddedMacros.Soinsteadofa"Event
Procedure",ourOnClickpropertiesgiveus"EmbeddedMacro".

We'regoingtochangetheMoreInfobuttononourDepartmentsSubFormtoshowustheemployee's
picture.

1. OpentheDepartmentsSubFormindesignview

2. OpenthepropertiesfortheMoreInfobutton

3. Changethelookofthebutton
a. FormatTabclickinthePictureproperty
b. Clickontheattheendoftheline
c. FindtheHappyFaceandclickOK

4. Changetheevent
a. EventTabclickinthe
OnClickproperty
b. Clickontheatthe
endoftheline
c. AddaNewAction
i. GoToControl
ii. ControlName
Picture
d. CloseandSave

5. Testthebutton

Page10


MacroActions

HereisalistofalltheMacroactions.Ifyoudon'tseethemonyourlist,besureto
turnontheShowAllActionsbuttonintheShow/HidegroupontheMacroTools
DesignTab.

Comment

ImportSharePointList

RunMacro

Group

LockNavigationPane

RunMenuCommand

If

MaximizeWindow

RunSavedImportExport

SubMacro

MessageBox

RunSql

AddContactFromOutlook

MinimizeWindow

SaveAsOutlookContact

AddMenu

MoveAndSizeWindow

SaveObject

ApplyFilter

NavigateTo

SaveRecord

Beep

OnError

SearchForRecord

BrowseTo

OpenForm

SelectObject

CancelEvent

OpenQuery

SendKeys

ClearMacroError

OpenReport

SetDisplayedCategories

CloseDatabase

OpenSharepointList

SetFilter

CloseWindow

OpenSharePointRecycleBin

SetLocalVar

CollectDataViaEmail

OpenTable

SetMenuItem

CopyObject

OpenVisualBasicModule

SetOrderBy

DeleteObject

PrintObject

SetProperty

DeleteRecord

PrintOut

SetTempVar

DisplayHourGlassPointer

PrintPreview

SetValue

Echo

QuitAccess

SetWarnings

EditListItems

Redo

ShowAllRecord's

EmailDatabaseObject

Refresh

ShowToolbar

ExportWithFormatting

RefreshRecord

SingleStep

FindNextRecord

RemoveTempVar

StartNewWorkflow

FindRecord

RenameObject

StopAllMacros

GoToControl

RepaintObject

StopMacro

GoToPage

Requery

UndoRecord

GoToRecord

RestoreWindow

WordMailMerge

ImportExportData

RunApplication

WorkflowTasks

ImportExportSpreadsheet

RunCode

ImportExportText

RunDataMacro
Page11


NonButtonMacros
Whileweusebuttonstoactivatemacrositispossibletohave
themrunautomatically,inthebackground.Button'sruna
macrooreventprocedureontheeventthattheyare'clicked'.
Buttherearelotsofothereventsthatcantriggeramacroor
eventprocedure.

We'regoingtocreateabuttonthatwillrunwhenaformisclosed.EachtimewecloseaFormwewould
liketheMainMenutoopen.Let'screateasimplemacrothatopenstheMainMenu.

1. FromtheCreateTab,chooseMacro

2. FromtheActionList,chooseOpenForm

3. FromtheFormName,chooseMainMenu

4. Closeandsaveas"ReturntoMain"

Wecouldcreateamacrothatwouldclosetheformandthen
openthemainmenu,butwhatiftheyusetheXinthecorner,
orthekeyboardshortcuts(CtrlW,CtrlF4)?Nomatterhowthe
formisclosed,wewouldliketheMainMenutoopen.We're
goingtoassignthismacrotorunanytimeaformisclosed.

1. OpenthePatient'sForminDesignView

2. OpenthePropertySheetfortheForm

3. TurntotheEventTab

4. SetpropertyOnClosetobeReturntoMain

5. Repeatforeachoftheothermainforms
a. PatientVisits,Departments,andEmployees
b. InDesignviewsetpropertyOnClosetobe
ReturntoMain

Help
SomeoftheEventnamesarenotclear.Thisistrueofmany
ofthepropertyoptions.Watchyourstatusbarasyouclick
insideeachpropertyoption,you'llseeasmalldescription
thatmayhelp.

BeyondthatthereishelpthroughtheAccessHelpbutton ,
onlinethroughtheMicrosoftSupport,amyriadofonline
forums,andofcourseme.I'mhappytohelpthebestIcan.

Andplease,trytoavoidtheVBACodeifyoucan.
Page12

Das könnte Ihnen auch gefallen