Public Function IdentifyBrokenReference() As Boolean
'Return whether or not broken references are identified
'within the current project
IdentifyBrokenReference = Application.BrokenReference
End Function
Sub CompactRepairDB()
Dim strFilePath As String
'Store path of current database in a variable
strFilePath = CurrentProject.Path
'If destination database exists, delete it
If Len(Dir(strFilePath & “\Chap8Small.mdb”)) Then
Kill strFilePath & “\Chap8Small.mdb”
End If
'Use the CompactRepair method of the Application object
'to compact and repair the database
Application.CompactRepair strFilePath & “\Chap9Big.accdb”, _
strFilePath & “\Chap9Small.accdb”, True
End Sub
Sub ConvertAccessDatabase()
Dim strFilePath As String
'Store current file path into variable
strFilePath = CurrentProject.Path
'Delete destination database if it exists
If Len(Dir(strFilePath & “\ChapV2007.accdb”)) Then
Kill strFilePath & “\Chap9V2007.accdb”
End If
'Convert source database to Access 2007 file format
Application.ConvertAccessProject strFilePath & “\Chap9Ex.mdb”, _
strFilePath & “\Chap9V2007.accdb”, _
DestinationFileFormat:=acFileFormatAccess2007
End Sub
Sub IterateOpenForms()
'Declare a form object variable
Dim frm As Form
'Use the form object variable to point at each form in the Forms collection
For Each frm In Forms
'Print the name of the referenced form to the Immediate window
Debug.Print frm.Name
Next frm
End Sub
Sub IterateOpenReports()
'Declare a report object variable
Dim rpt As Report
'Use the report object variable to point at each report in the Reports collection
For Each rpt In Reports
'Print the name of the referenced report to the Immediate window
Debug.Print rpt.Name
Next rpt
End Sub
Sub CurrentProjectObject()
With CurrentProject
Debug.Print .Name
Debug.Print .Path
End With
End Sub
Sub IterateAllForms()
Dim vnt As Variant
'Loop through each form in the current project,
'printing the name of each form to the Immediate window
With CurrentProject
For Each vnt In .AllForms
Debug.Print vnt.Name
Next vnt
End With
End Sub
Sub IterateAllReports()
'Declare iteration variable
Dim vnt As Variant
'Loop through each report in the current project,
'printing the name of each report to the Immediate window
With CurrentProject
For Each vnt In .AllReports
Debug.Print vnt.Name
Next vnt
End With
End Sub
Sub IterateAllMacros()
'Declare iteration variable
Dim vnt As Variant
'Loop through each macro in the current project,
'printing the name of each macro to the Immediate window
With CurrentProject
For Each vnt In .AllMacros
Debug.Print vnt.Name
Next vnt
End With
End Sub
Sub IterateAllModules()
'Declare iteration variable
Dim vnt As Variant
'Loop through each module in the current project,
'printing the name of each module to the Immediate window
With CurrentProject
For Each vnt In .AllModules
Debug.Print vnt.Name
Next vnt
End With
End Sub
Sub IterateAllTables()
'Declare looping variable
Dim vnt As Variant
'Loop through each table in the database
'referenced by the CurrentData object
With CurrentData
For Each vnt In .AllTables
'Print the name of the table
Debug.Print vnt.Name
Next vnt
End With
End Sub
Sub IterateAllQueries()
'Declare looping variable
Dim vnt As Variant
'Loop through each query in the database
'referenced by the CurrentData object
With CurrentData
For Each vnt In .AllQueries
'Print the name of the table
Debug.Print vnt.Name
Next vnt
End With
End Sub
DoCmd.OpenQuery "qryCustomers", acViewNormal, acReadOnly
Public Sub GetDates()
'Declare looping variable
Dim vnt As Variant
'Loop through each table in the database
'referenced by the CurrentData object
With CurrentData
For Each vnt In .AllTables
'Print the name, date created, and the date
'the table was last modified
Debug.Print vnt.Name & “, “ & _
vnt.DateCreated & “, “ & _
vnt.DateModified
Next vnt
End With
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'If the Save command button is not already enabled
If Not cmdSave.Enabled Then
'If a relevant key was pressed
If ImportantKey(KeyCode, Shift) Then
'Flip the command buttons on the form,
'setting focus to the active control
Call FlipEnabled(Me, Screen.ActiveControl)
'Disable the cboSelectClient combo box
Me.cboSelectClient.Enabled = False
End If
'If the Save button is already enabled (form is dirty)
'ignore the PageUp and PageDown keys
Else
If KeyCode = vbKeyPageDown Or _
KeyCode = vbKeyPageUp Then
KeyCode = 0
End If
End If
End Sub
Function ImportantKey(KeyCode, Shift)
'Set return value to false
ImportantKey = False
'If Alt key was pressed, exit function
If Shift = acAltMask Then
Exit Function
End If
'If Delete, Backspace, or a typeable character was pressed
If KeyCode = vbKeyDelete Or KeyCode = vbKeyBack Or (KeyCode > 31 _
And KeyCode < 256) Then
'If the typeable character was NOT a right, left, up,
'or down arrow, page up, or page down, return True
If KeyCode = vbKeyRight Or KeyCode = vbKeyLeft Or _
KeyCode = vbKeyUp Or KeyCode = vbKeyDown Or _
KeyCode = vbKeyPageUp Or KeyCode = vbKeyPageDown Then
Else
ImportantKey = True
End If
End If
End Function
Sub FlipEnabled(frmAny As Form, ctlAny As Control)
'Declare a control object variable
Dim ctl As Control
'If the type of control received as a parameter
'is a command button, enable it and set focus to it
ctlAny.Enabled = True
ctlAny.SetFocus
'Loop through each control in the controls collection
'of the form that was received as a parameter
For Each ctl In frmAny.Controls
'If the type of the control is a command button
'and the name of the control does not match the
'name of the control received as a parameter
'flip the enabled property of the control
If ctl.ControlType = acCommandButton Then
If ctl.Name <> ctlAny.Name Then
ctl.Enabled = Not ctl.Enabled
End If
End If
Next ctl
End Sub
Private Sub cmdSave_Click()
'Save changes to the client record
DoCmd.RunCommand acCmdSaveRecord
'Enable client selection combo
Me.cboSelectClient.Enabled = True
'Call routine to disable save and cancel and
'enable view projects
Call FlipEnabled(Me, Me.cboSelectClient)
End Sub
Private Sub cmdUndo_Click()
'Undo changes
DoCmd.RunCommand acCmdUndo
'Enable client selection combo
Me.cboSelectClient.Enabled = True
'Call routine to disable save and cancel and
'enable view projects
Call FlipEnabled(Me, Me.cboSelectClient)
End Sub
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)