Archive | Access RSS feed for this section

Delete Event

15 May

From:    “Sofyan Efendi” <sofyan@madinah.cc>
Date:    Wed, 16 Aug 2006 16:48:25 +0700

Event Delete terjadi saat user melakukan proses delete record, baik menggunakan perintah delete maupun menggunakan tombol DEL pada keyboard. Event ini terjadi sebelum record tersebut benar-benar terhapus. Syntax:

Private Sub Form_Delete( Cancel As Integer)

Penjelasan:

– Cancel: Jika diset True (-1) maka akan meng-cancel event Delete.

Contoh:

Private Sub Form_Delete( Cancel As Integer)
Cancel = True
MsgBox “This record can’t be deleted.”
End Sub

Wassalaamu’alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi
– AccessWeb <http://www35.websamba.com/accessweb&gt;
– OPI-Homepage <http://www.geocities.com/opi1978&gt;

Dirty Event

14 May

From:    “Sofyan Efendi” <sofyan@madinah.cc>
Date:    Fri, 18 Aug 2006 15:00:28 +0700

Event Dirty terjadi saat isi dari form atau text box atau combo box berubah. Event ini terjadi pula saat kita berpindah dari page satu ke page lainnya dalam suatu tab control. Syntax:

Private Sub Form_Dirty(Cancel As Integer)

Penjelasan:

– Cancel: Jika diisi True maka akan meng-cancel event ini.

Urutan event ini adalah:

KeyDown > KeyPress > BeforeInsert > Dirty > KeyUp

Contoh:

Private Sub Form_Dirty()
If Me.Dirty Then
Me!btnUndo.Enabled = True ‘ Enable button.
Else
Me!btnUndo.Enabled = False ‘ Disable button.
End If
End Sub

Sub btnUndo_Click( )
Dim ctlC As Control
‘ For each control.
For Each ctlC in Me.Controls
If ctlC.ControlType = acTextBox Then
‘ Restore Old Value.
ctlC.Value = ctlC.OldValue
End If
Next ctlC
End Sub

Wassalaamu’alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi
– AccessWeb <http://www35.websamba.com/accessweb&gt;
– OPI-Homepage <http://www.geocities.com/opi1978&gt;

ItemAdded and ItemRemoved Event

14 May

From:    “Sofyan Efendi” <sofyan@madinah.cc>
Date:    Fri, 18 Aug 2006 16:04:26 +0700

Event ItemAdded terjadi saat reference VBA ditambah di dalam suatu project Visual Basic Access. Syntax:

Private Sub ReferencesName_ ItemAdded( ByVal Reference As _
Access.Reference)

Sedangkan event ItemRemoved terjadi saat reference VBA dihilangkan di dalam suatu project Visual Basic Access. Syntax:

Private Sub ReferencesName_ ItemAdded( ByVal Reference As _
Access.Reference)

Penjelasan:

– ReferencesName: Nama variable yang telah definisikan sebagai reference.

– Reference: Nama reference yang baru ditambah.

Contoh 1:

The following example includes event procedures for the ItemAdded and ItemRemoved events. To try this example, first create a new class module by clicking Class Module on the Insert menu. Paste the following code into the class module and save the module as RefEvents:

‘ Declare object variable to represent References collection.
Public WithEvents evtReferences As References

‘ When instance of class is created, initialize evtReferences
‘ variable.
Private Sub Class_Initialize( )
Set evtReferences = Application. References
End Sub

‘ When instance is removed, set evtReferences to Nothing.
Private Sub Class_Terminate( )
Set evtReferences = Nothing
End Sub

‘ Display message when reference is added.
Private Sub evtReferences_ ItemAdded( ByVal Reference As _
Access.Reference)
MsgBox “Reference to ” & Reference.Name & ” added.”
End Sub

‘ Display message when reference is removed.
Private Sub evtReferences_ ItemRemoved( ByVal Reference As _
Access.Reference)
MsgBox “Reference to ” & Reference.Name & ” removed.”
End Sub

Contoh 2:

The following Function procedure adds a specified reference. When a reference is added, the ItemAdded event procedure defined in the RefEvents class runs. For example, to set a reference to the calendar control, you could pass the string “C:\Windows\ System\Mscal. ocx”, if this is the correct location for the calendar control on your computer.

‘ Create new instance of RefEvents class.
Dim objRefEvents As New RefEvents

‘ Pass file name and path of type library to this procedure.
Function AddReference( strFileName As String) As Boolean
Dim ref As Reference

On Error GoTo Error_AddReference
‘ Create new reference on References object variable.
Set ref = objRefEvents. evtReferences. AddFromFile( strFileName)
AddReference = True

Exit_AddReference:
Exit Function

Error_AddReference:
MsgBox Err & “: ” & Err.Description
AddReference = False
Resume Exit_AddReference
End Function

Wassalaamu’alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi
– AccessWeb <http://www35.websamba.com/accessweb&gt;
– OPI-Homepage <http://www.geocities.com/opi1978&gt;

KeyDown Event

14 May

From:    “Sofyan Efendi” <sofyan@madinah.cc>
Date:    Tue, 22 Aug 2006 11:05:00 +0700

Event KeyDown terjadi ketika user menekan suatu tombol pada keyboard pada saat user sedang aktif (focus) pada suatu form atau control. Syntax:

Private Sub object_KeyDown( KeyCode As Integer, Shift As Integer)

Penjelasan:

– Object: Nama Form atau control di dalam Form.

– KeyCode: Kode tombol, misalnya vbKeyF1 berarti tombol F1 atau vbKeyHome berarti tombol HOME key). Untuk menjaga suatu form atau control dari penekanan suatu tombol, dapat mensetting KeyCode ke 0.

Shift: Yakni penekanan tombol SHIFT, CTRL, dan ALT saat event ini dilakukan. Isilah dengan constants sbb:

. acShiftMask -> The bit mask for the SHIFT key.
. acCtrlMask -> The bit mask for the CTRL key.
. acAltMask -> The bit mask for the ALT key.

Urutan event ini adalah:

KeyDown -> KeyPress -> KeyUp

Jika ditambah dengan event Change, maka urutannya adalah:

KeyDown -> KeyPress -> Change -> KeyUp

Jika event KeyDown menyebabkan berpindahnya focus ke control yang lain, maka urutan event nya adalah:

– First control:
KeyDown -> BeforeUpdate -> AfterUpdate -> Exit -> LostFocus

– Second control:
Enter -> GotFocus -> KeyPress -> KeyUp

Contoh:

Private Sub KeyHandler_KeyDown( KeyCode As Integer, _
Shift As Integer)
Dim intShiftDown As Integer, intAltDown As Integer
Dim intCtrlDown As Integer

‘ Use bit masks to determine which key was pressed.
intShiftDown = (Shift And acShiftMask) > 0
intAltDown = (Shift And acAltMask) > 0
intCtrlDown = (Shift And acCtrlMask) > 0
‘ Display message telling user which key was pressed.
If intShiftDown Then MsgBox “You pressed the SHIFT key.”
If intAltDown Then MsgBox “You pressed the ALT key.”
If intCtrlDown Then MsgBox “You pressed the CTRL key.”
End Sub

Wassalaamu’alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi
– AccessWeb <http://www35.websamba.com/accessweb&gt;
– OPI-Homepage <http://www.geocities.com/opi1978&gt;

KeyPress Event

14 May

From:    “Sofyan Efendi” <sofyan@madinah.cc>
Date:    Tue, 22 Aug 2006 11:11:10 +0700

Event KeyPress terjadi saat user menekan tombol pada keyboard dan menahannya sesaat atau sebelum tombol tersebut dilepas kembali keatas. Syntax:

Private Sub object_KeyPress( KeyAscii As Integer)

Penjelasan:

– Object: Nama Form atau control di dalam Form.

– KeyAscii: Yakni setting kode Ascii yang dihasilkan. Menset KeyAscee ke dalam 0 akan menyebabkan event ini di cancel, sehingga user tidak akan melihat hasil ketikkannya pada control.

Contoh:

Private Sub ShipRegion_KeyPress (KeyAscii As Integer)
Dim strCharacter As String

‘ Convert ANSI value to character string.
strCharacter = Chr(KeyAscii)
‘ Convert character to upper case, then to ANSI value.
KeyAscii = Asc(UCase(strCharac ter))
End Sub

Wassalaamu’alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi
– AccessWeb <http://www35.websamba.com/accessweb&gt;
– OPI-Homepage <http://www.geocities.com/opi1978&gt;

KeyUp Event

14 May

From:    “Sofyan Efendi” <sofyan@madinah.cc>
Date:    Tue, 22 Aug 2006 11:16:21 +0700

Event KeyUp terjadi ketika tombol keyboard yang ditekan tersebut dilepas kembali keatas. Syntax:

Private Sub object_KeyUp( KeyCode As Integer, Shift As Integer)

Penjelasan:

– Object: Nama Form atau control di dalam Form.

– KeyCode: Kode tombol, misalnya vbKeyF1 berarti tombol F1 atau vbKeyHome berarti tombol HOME key). Untuk menjaga suatu form atau control dari penekanan suatu tombol, dapat mensetting KeyCode ke 0.

– Shift: Yakni penekanan tombol SHIFT, CTRL, dan ALT saat event ini dilakukan. Isilah dengan constants sbb:

. acShiftMask -> The bit mask for the SHIFT key.
. acCtrlMask -> The bit mask for the CTRL key.
. acAltMask -> The bit mask for the ALT key.

Contoh:

Private Sub KeyHandler_KeyUp( KeyCode As Integer, _
Shift As Integer)
Dim intShiftUp As Integer, intAltUp As Integer
Dim intCtrlUp As Integer

‘ Use bit masks to determine which key was pressed.
intShiftUp = (Shift And acShiftMask) > 0
intAltUp = (Shift And acAltMask) > 0
intCtrlUp = (Shift And acCtrlMask) > 0
‘ Display message telling user which key was pressed.
If intShiftUp Then MsgBox “You pressed the SHIFT key.”
If intAltUp Then MsgBox “You pressed the ALT key.”
If intCtrlUp Then MsgBox “You pressed the CTRL key.”
End Sub

Wassalaamu’alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi
– AccessWeb <http://www35.websamba.com/accessweb&gt;
– OPI-Homepage <http://www.geocities.com/opi1978&gt;

MouseDown Event

14 May

From:    “Sofyan Efendi” <sofyan@madinah.cc>
Date:    Tue, 22 Aug 2006 14:12:51 +0700

Event MouseDown terjadi ketika user menekan tombol mouse ke bawah, pada saat user sedang aktif (focus) pada suatu form atau control. Syntax:

Private Sub object_MouseDown( Button As Integer, Shift As Integer, X As Single, Y As Single)

Penjelasan:

– Object: Nama Form, Form section, atau control di dalam suatu Form.

– Button: TOmbol mouse yang ditekan. Isilah dengan constants sbb:

. acLeftButton -> The bit mask for the left mouse button.
. acRightButton -> The bit mask for the right mouse button.
. acMiddleButton The bit mask for the middle mouse button.

– Shift: Yakni penekanan tombol SHIFT, CTRL, dan ALT saat event ini dilakukan. Isilah dengan constants sbb:

. acShiftMask -> The bit mask for the SHIFT key.
. acCtrlMask -> The bit mask for the CTRL key.
. acAltMask -> The bit mask for the ALT key.

– X, Y: Yakni posisi koordinat x dan y mouse pointer pada object dalam satuan twips.

Contoh:

Private Sub Form_MouseDown( Button As Integer, _
Shift As Integer, X As Single, _
Y As Single)
If Button = acLeftButton Then
MsgBox “You pressed the left button.”
End If
If Button = acRightButton Then
MsgBox “You pressed the right button.”
End If
If Button = acMiddleButton Then
MsgBox “You pressed the middle button.”
End If
End Sub

Wassalaamu’alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi
– AccessWeb <http://www35.websamba.com/accessweb&gt;
– OPI-Homepage <http://www.geocities.com/opi1978&gt;

MouseWheel Event

14 May

From:    “Sofyan Efendi” <sofyan@madinah.cc>
Date:    Tue, 22 Aug 2006 14:24:29 +0700

Event MouseWheel terjadi saat user memutar scroll mouse (baik kedepan maupun kebelakang) pada saat sedang aktif pada Form View, Datasheet View, PivotChart View, atau PivotTable View. Syntax:

Private Sub Form_MouseWheel( ByVal Page As Boolean, ByVal Count As Long)

Penjelasan:

– Page: Akan bernilai True jika halaman form sudah berganti, akibat dari pemutaran scroll mouse.

– Count: Jumlah halaman yang terlewati yang diakibatkan berputarnya scroll mouse.

Contoh:

Private Sub Form_MouseWheel( _
ByVal Page As Boolean, ByVal Count As Long)
If Page = True Then
MsgBox “You’ve moved to another page.”
End If
End Sub

Wassalaamu’alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi
– AccessWeb <http://www35.websamba.com/accessweb&gt;
– OPI-Homepage <http://www.geocities.com/opi1978&gt;

MouseMove Event

14 May

From:    “Sofyan Efendi” <sofyan@madinah.cc>
Date:    Tue, 22 Aug 2006 14:16:04 +0700

Event MouseMove terjadi saat user menggerakkan pointer mouse. Syntax:

Private Sub object_MouseMove( Button As Integer, Shift As Integer, X As Single, Y As Single)

Penjelasan:

– Object: Nama Form, Form section, atau control di dalam suatu Form.

– Button: TOmbol mouse yang ditekan. Isilah dengan constants sbb:

. acLeftButton -> The bit mask for the left mouse button.
. acRightButton -> The bit mask for the right mouse button.
. acMiddleButton The bit mask for the middle mouse button.

– Shift: Yakni penekanan tombol SHIFT, CTRL, dan ALT saat event ini dilakukan. Isilah dengan constants sbb:

. acShiftMask -> The bit mask for the SHIFT key.
. acCtrlMask -> The bit mask for the CTRL key.
. acAltMask -> The bit mask for the ALT key.

– X, Y: Yakni posisi koordinat x dan y mouse pointer pada object dalam satuan twips.

Contoh:

Private Sub Detail_MouseMove( Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Dim intShiftDown As Integer, intLeftButton As Integer

Me!Coordinates. Caption = X & “, ” & Y
‘ Use bit masks to determine state of
‘ SHIFT key and left button.
intShiftDown = Shift And acShiftMask
intLeftButton = Button And acLeftButton
‘ Check that SHIFT key and left button
‘ are both pressed.
If intShiftDown And intLeftButton > 0 Then
MsgBox “Shift key and left mouse button were pressed.”
End If
End Sub

Wassalaamu’alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi
– AccessWeb <http://www35.websamba.com/accessweb&gt;
– OPI-Homepage <http://www.geocities.com/opi1978&gt;

MouseUp Event

14 May

From:    “Sofyan Efendi” <sofyan@madinah.cc>
Date:    Tue, 22 Aug 2006 14:19:45 +0700

Event MouseUp terjadi saat user melepas ke atas tombol mouse, pada saat user sedang aktif (focus) pada suatu form atau control. Syntax:

Private Sub object_MouseUp( Button As Integer, Shift As Integer, X As Single, Y As Single)

Penjelasan:

– Object: Nama Form, Form section, atau control di dalam suatu Form.

– Button: TOmbol mouse yang ditekan. Isilah dengan constants sbb:

. acLeftButton -> The bit mask for the left mouse button.
. acRightButton -> The bit mask for the right mouse button.
. acMiddleButton The bit mask for the middle mouse button.

– Shift: Yakni penekanan tombol SHIFT, CTRL, dan ALT saat event ini dilakukan. Isilah dengan constants sbb:

. acShiftMask -> The bit mask for the SHIFT key.
. acCtrlMask -> The bit mask for the CTRL key.
. acAltMask -> The bit mask for the ALT key.

– X, Y: Yakni posisi koordinat x dan y mouse pointer pada object dalam satuan twips.

Contoh:

Private Sub Form_MouseUp( Button As Integer, _
Shift As Integer, X As Single, _
Y As Single)
If Button = acLeftButton Then
MsgBox “You pressed the left button.”
End If
If Button = acRightButton Then
MsgBox “You pressed the right button.”
End If
If Button = acMiddleButton Then
MsgBox “You pressed the middle button.”
End If
End Sub

Wassalaamu’alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi
– AccessWeb <http://www35.websamba.com/accessweb&gt;
– OPI-Homepage <http://www.geocities.com/opi1978&gt;