Creating Simple Application using MS Access Forms Object Model

This article specificly focus on creating Application by accessing object Model .In order to facilitate automation in MS Access VBA are alternative over VBA. This feature could be exploited in numerous ways to do accomplish various task.To implement this concept first of all we need to create a Database containing a Form named frmChkr.As shown in figure form contains basic MS Access Controls

Creating Simple Application using MS Access  Forms Object Model Fig 1.1

Fig 1.1

In this particular case we will use form property through Microsoft Access object models to automate some sort of Artificial intelligence .when User open a form screen will appear as shown below

Creating Simple Application using MS Access  Forms Object Model Fig 1.2

Fig 1.2

As shown in above figure,we have associated a macro named DataMacro1 with After Insert Event of Table named tblStudent. In order to complete above step ,we first need to create a Macro named DataMacro1.This macro have been shown in figure fig 1.3,As shown below Macro contains code for updating fields in another table named tblStudetails.

Creating Simple Application using MS Access  Forms Object Model Fig 1.3

Fig 1.3

After inserting records in table tblStudent values would be subsequently updated into another table as well. Similar operation could be performed for other scenerio as well like when some record going to be deleted,updated etc.

VBA Code associated with different form buttons:-

Private Sub cmdEight_Click()
If Nz(Me.cmdEight.Caption, 0) <> "+" Then
Me.cmdEight.Caption = "*"
End If
processingValues ("cmdEight")
winner "cmdEight"
End Sub
Private Sub cmdfive_Click()
If Nz(Me.cmdfive.Caption, 0) <> "+" Then
Me.cmdfive.Caption = "*"
End If
processingValues ("cmdfive")
winner "cmdfive"
End Sub
Private Sub cmdfour_Click()
If Nz(Me.cmdfour.Caption, 0) <> "+" Then
Me.cmdfour.Caption = "*"
End If
processingValues ("cmdfour")
winner "cmdfour"
End Sub
Private Sub cmdNine_Click()
If Nz(Me.cmdNine.Caption, 0) <> "+" Then
Me.cmdNine.Caption = "*"
End If
processingValues ("cmdNine")
winner "cmdNine"
End Sub
Private Sub cmdOne_Click()
If Nz(Me.cmdOne.Caption, 0) <> "+" Then
Me.cmdOne.Caption = "*"
End If
processingValues ("cmdOne")
winner ("cmdOne")
End Sub
Private Sub cmdSeven_Click()
If Nz(Me.cmdSeven.Caption, 0) <> "+" Then
Me.cmdSeven.Caption = "*"
End If
processingValues ("cmdSeven")
winner "cmdSeven"
End Sub
Private Sub cmdSix_Click()
If Nz(Me.cmdSix.Caption, 0) <> "+" Then
Me.cmdSix.Caption = "*"
End If
processingValues ("cmdSix")
winner "cmdSix"
End Sub
Private Sub cmdthree_Click()
If Nz(Me.cmdthree.Caption, 0) <> "+" Then
Me.cmdthree.Caption = "*"
End If
processingValues ("cmdthree")
winner "cmdthree"
End Sub
Private Sub cmdtwo_Click()
If Nz(Me.cmdtwo.Caption, 0) <> "+" Then
Me.cmdtwo.Caption = "*"
End If
processingValues ("cmdtwo")
winner "cmdtwo"
End Sub
Public Function processingValues(value As String) ' function for determining next move
Dim ctrl As Control
Dim frm As Form
For Each ctrl In Forms("frmChkr").Controls
If ((ctrl.Properties("Caption") = "")) And value <> ctrl.Name Then
ctrl.Properties("Caption") = "+"
Exit Function
End If
Next ctrl
End Function
Public Function winner(captionData As String) ' function for determining continuous pattern
Dim Winningflag As Boolean
Dim WinData As Boolean
Select Case captionData
Case "cmdOne"
If (Me.cmdNine.Caption = "*" And Me.cmdEight.Caption = "*") Or (Me.cmdfour.Caption = "*" And Me.cmdthree.Caption = "*") Then
Winningflag = True
ElseIf (Me.cmdNine.Caption = "+" And Me.cmdEight.Caption = "+" And Me.cmdOne.Caption = "+") Or (Me.cmdfour.Caption = "+" And Me.cmdthree.Caption = "+" And Me.cmdOne.Caption = "+") Then
WinData = True
End If
Case "cmdtwo"
If (Me.cmdfive.Caption = "*" And Me.cmdfour.Caption = "*") Or (Me.cmdSix.Caption = "*" And Me.cmdNine.Caption = "*") Or (Me.cmdSeven.Caption = "*" And Me.cmdOne.Caption = "*") Then
Winningflag = True
ElseIf (Me.cmdfive.Caption = "+" And Me.cmdfour.Caption = "+" And Me.cmdtwo.Caption = "+") Or (Me.cmdSix.Caption = "+" And Me.cmdNine.Caption = "+" And Me.cmdtwo.Caption = "+") Or (Me.cmdSeven.Caption = "+" And Me.cmdOne.Caption = "+" And Me.cmdtwo.Caption = "+") Then
WinData = True
End If
Case "cmdthree"
If (Me.cmdOne.Caption = "*" And Me.cmdfour.Caption = "*") Or (Me.cmdSix.Caption = "*" And Me.cmdSeven.Caption = "*") Then
Winningflag = True
ElseIf (Me.cmdOne.Caption = "+" And Me.cmdfour.Caption = "+" And Me.cmdthree.Caption = "+") Or (Me.cmdSix.Caption = "+" And Me.cmdSeven.Caption = "+" And Me.cmdthree.Caption = "+") Then
WinData = True
End If
Case "cmdfour"
If (Me.cmdfive.Caption = "*" And Me.cmdtwo.Caption = "*") Or (Me.cmdNine.Caption = "*" And Me.cmdSeven.Caption = "*") Or (Me.cmdthree.Caption = "*" And Me.cmdOne.Caption = "*") Then
Winningflag = True
ElseIf (Me.cmdfive.Caption = "+" And Me.cmdtwo.Caption = "+" And Me.cmdfour.Caption = "+") Or (Me.cmdNine.Caption = "+" And Me.cmdSeven.Caption = "+" And Me.cmdfour.Caption = "+") Or (Me.cmdthree.Caption = "+" And Me.cmdOne.Caption = "+" And Me.cmdfour.Caption = "+") Then WinData = True
End If
Case "cmdfive"
If (Me.cmdEight.Caption = "*" And Me.cmdSeven.Caption = "*") Or (Me.cmdtwo.Caption = "*" And Me.cmdfour.Caption = "*") Then
Winningflag = True
ElseIf (Me.cmdEight.Caption = "+" And Me.cmdSeven.Caption = "+" And Me.cmdfive.Caption = "+") Or (Me.cmdfour.Caption = "+" And Me.cmdtwo.Caption = "+" And Me.cmdfive.Caption = "+") Then
WinData = True
End If
Case "cmdSix"
If (Me.cmdthree.Caption = "*" And Me.cmdSeven.Caption = "*") Or (Me.cmdtwo.Caption = "*" And Me.cmdNine.Caption = "*") Then
Winningflag = True
ElseIf (Me.cmdthree.Caption = "+" And Me.cmdSeven.Caption = "+" And Me.cmdSix.Caption = "+") Or (Me.cmdtwo.Caption = "+" And Me.cmdNine.Caption = "+" And Me.cmdSix.Caption = "+") Then
WinData = True
End If
Case "cmdSeven"
If (Me.cmdthree.Caption = "*" And Me.cmdSix.Caption = "*") Or (Me.cmdOne.Caption = "*" And Me.cmdtwo.Caption = "*") Or (Me.cmdNine.Caption = "*" And Me.cmdfour.Caption = "*") Or (Me.cmdEight.Caption = "*" And Me.cmdfive.Caption = "*") Then
Winningflag = True
ElseIf (Me.cmdthree.Caption = "+" And Me.cmdSix.Caption = "+" And Me.cmdSeven.Caption = "+") Or (Me.cmdOne.Caption = "+" And Me.cmdtwo.Caption = "+" And Me.cmdSeven.Caption = "+") Or (Me.cmdNine.Caption = "+" And Me.cmdfour.Caption = "+" And Me.cmdSeven.Caption = "+") Or (Me.cmdEight.Caption = "+" And Me.cmdfive.Caption = "+" And Me.cmdSeven.Caption = "+") Then
WinData = True
End If
Case "cmdEight"
If (Me.cmdNine.Caption = "*" And Me.cmdOne.Caption = "*") Or (Me.cmdSeven.Caption = "*" And Me.cmdfive.Caption = "*") Then
Winningflag = True
ElseIf (Me.cmdNine.Caption = "+" And Me.cmdOne.Caption = "+" And Me.cmdEight.Caption = "+") Or (Me.cmdSeven.Caption = "+" And Me.cmdfive.Caption = "+" And Me.cmdEight.Caption = "+") Then
WinData = True
End If
Case "cmdNine"
If (Me.cmdSix.Caption = "*" And Me.cmdtwo.Caption = "*") Or (Me.cmdSeven.Caption = "*" And Me.cmdfour.Caption = "*") Or (Me.cmdEight.Caption = "*" And Me.cmdOne.Caption = "*") Then
Winningflag = True
ElseIf (Me.cmdSix.Caption = "+" And Me.cmdtwo.Caption = "+" And Me.cmdNine.Caption = "+") Or (Me.cmdSeven.Caption = "+" And Me.cmdfour.Caption = "+" And Me.cmdNine.Caption = "+") Or (Me.cmdEight.Caption = "+" And Me.cmdOne.Caption = "+" And Me.cmdNine.Caption = "+") Then
WinData = True
End If
End Select
If Winningflag Then
MsgBox "You have created a pattern", vbOKOnly, "Winner"
DoCmd.Close acForm, Me.Name
ElseIf WinData Then
MsgBox "You have not created a pattern", vbOKOnly, "Lost the chance"
DoCmd.Close acForm, Me.Name
End If
End Function
Private Sub Form_Open(Cancel As Integer)
MsgBox "Press button to procees", vbInformation, "Access Cheker"
End Sub


DISCLAIMER

It is advised that the information provided in the article should not be used for any kind formal or production programming purposes as content of the article may not be complete or well tested. Access Guru will not be responsible for any kind of damage (monetary, time, personal or any other type) which may take place because of the usage of the content in the article.