7/1/09

Few important VB codes

(Search code):
(Use Combo box)

default:
Private Sub Comboname_BeforeUpdate(Cancel As Integer)

End Sub

Change to:
Private Sub Comboname_afterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[BADGE] = " & Str(Me![Comboname])
Me.Bookmark = rs.Bookmark
End Sub



(To open a Form)or link to a Form:
(Use Command button)

Private Sub Commandname_Click()

On Error GoTo Err_Commandname_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Form name"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Commandname_Click:
Exit Sub

Err_Commandname_Click:
MsgBox Err.Description
Resume Exit_Commandname_Click

End Sub

(Close Button code): (It is much better if command name and caption is the same.
(Use Command Button)

Private Sub commandname_Click()
On Error GoTo Err_Commandname_Click


DoCmd.Quit

Exit_Commandname_Click:
Exit Sub

Err_Commandname_Click:
MsgBox Err.Description
Resume Exit_Commandname_Click
End Sub



Hints for Making Microsoft Acess database:
1.) Create table either in wizard or design view
2.) Enter the fields needed.
3.) Queries-design view-set the fields you want to appear in your report-
4.) Forms -design view-then design command button you want to click that usually opens your report. It depends on how you want your forms to look like.
5.) Reports-design view-then make the design that you want to appear in your reports. then just make sure you set the control source from the queries.

No comments:

Post a Comment