'--------------------------------------------------------------------------------------' Module : SRIS - Student Resource Information System ' Author : SirReynan ' Subject : CS313 DBMS - Database Management System ' Date

: 9/8/2013 ' Purpose : To be able to know the basic of database CODING techniques using predefined path and not by _ ' : physical address ' Requirements; ' : Add your own code for data environment using app.path and ' : Create your own code for datareport print outs ' : Add photo in your database registration process. ' Good LUCK!!! '--------------------------------------------------------------------------------------Dim SaveAdd As Boolean Dim DeleteProgress As Boolean Dim Ownership As String Dim sksuIT Private Sub cboCourse_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And cboCourse <> "" Then cboMajor.SetFocus End If End Sub Private Sub cboGender_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And cboGender <> "" Then txtAddress.SetFocus SendKeys "{Home}+{End}" End If End Sub Private Sub cboMajor_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And cboMajor <> "" Then cmdSave_Click End If End Sub Private Sub cmdAdd_Click()

'action taken when the cmdAdd Button caption is &Add If cmdAdd.Caption = "&Add" Then txtName.SetFocus DisableButtons UnlockInput SaveAdd = True cmdSave.Enabled = True cmdEdit.Enabled = False cmdAdd.Caption = "&Cancel" ' prepare all textboxes for adding by emptying each content txtName.Text = "" txtAge.Text = "" cboGender.Text = "" txtAddress.Text = "" txtMobile.Text = "" txtEmail.Text = "" cboCourse.Text = "" cboMajor.Text = "" If Data1.Recordset.BOF Then txtIDNo.Text = "00001" Else Data1.Recordset.MoveLast txtIDNo.Text = Format(Data1.Recordset.Fields("IDNo") + 1, "0000#") Data1.Refresh End If Else 'action taken when the cmdAdd Button caption is &Cancel On Error Resume Next Data1.Recordset.CancelUpdate EnableButtons LockedInput cmdSave.Enabled = False cmdEdit.Enabled = True

cmdAdd.Caption = "&Add" ' if transaction was cancelled then refresh the database ny displaying the content to the textboxes txtIDNo.Text = Data1.Recordset.Fields("IDNo") txtName.Text = Data1.Recordset.Fields("Name") txtAge.Text = Data1.Recordset.Fields("Age") cboGender.Text = Data1.Recordset.Fields("Gender") txtAddress.Text = Data1.Recordset.Fields("Address") txtMobile.Text = Data1.Recordset.Fields("Mobile") txtEmail.Text = Data1.Recordset.Fields("Email") cboCourse.Text = Data1.Recordset.Fields("Course") cboMajor.Text = Data1.Recordset.Fields("Major") End If End Sub Private Sub cmdDelete_Click() If Data1.Recordset.RecordCount = 0 Then If Data1.Recordset.RecordCount = 0 Then MsgBox "Database is empty.", vbInformation, "No Records!" DisableButtons cmdEdit.Enabled = False Form_Load End If Else With Data1.Recordset DeleteProgress = True warn_delete = MsgBox("Are you sure you want to delete this record? ", vbYesNo + vbCritical, "Warning!") If warn_delete = vbYes Then fra1.Visible = True fra1.Caption = "Deleting record..." DeleteProgress = True 'pass the delete command function to tmrProgress tmrProgress.Enabled = True EnableButtons End If

End With End If End Sub Private Sub cmdEdit_Click() 'action taken when the cmdEdit Button caption is &Edit If cmdEdit.Caption = "&Edit" Then UnlockInput Data1.Recordset.Edit txtName.SetFocus SendKeys "{Home}+{End}" DisableButtons SaveAdd = False cmdSave.Enabled = True cmdAdd.Enabled = False cmdEdit.Caption = "&Cancel" Else 'action taken when the cmdEdit Button caption is &Cancel Data1.Recordset.CancelUpdate EnableButtons cmdSave.Enabled = False cmdEdit.Enabled = True cmdAdd.Enabled = True cmdEdit.Caption = "&Edit" End If End Sub Private Sub cmdFirst_Click() Data1.Recordset.MoveFirst cmdFirst.Enabled = False cmdPrevious.Enabled = False cmdLast.Enabled = True cmdNext.Enabled = True txtIDNo.Text = Data1.Recordset.Fields("IDNo") txtName.Text = Data1.Recordset.Fields("Name") txtAge.Text = Data1.Recordset.Fields("Age")

cboGender.Text = Data1.Recordset.Fields("Gender") txtAddress.Text = Data1.Recordset.Fields("Address") txtMobile.Text = Data1.Recordset.Fields("Mobile") txtEmail.Text = Data1.Recordset.Fields("Email") cboCourse.Text = Data1.Recordset.Fields("Course") cboMajor.Text = Data1.Recordset.Fields("Major") End Sub Private Sub cmdLast_Click() Data1.Recordset.MoveLast cmdLast.Enabled = False cmdNext.Enabled = False cmdFirst.Enabled = True cmdPrevious.Enabled = True txtIDNo.Text = Data1.Recordset.Fields("IDNo") txtName.Text = Data1.Recordset.Fields("Name") txtAge.Text = Data1.Recordset.Fields("Age") cboGender.Text = Data1.Recordset.Fields("Gender") txtAddress.Text = Data1.Recordset.Fields("Address") txtMobile.Text = Data1.Recordset.Fields("Mobile") txtEmail.Text = Data1.Recordset.Fields("Email") cboCourse.Text = Data1.Recordset.Fields("Course") cboMajor.Text = Data1.Recordset.Fields("Major") End Sub Private Sub cmdNext_Click() cmdFirst.Enabled = True cmdPrevious.Enabled = True With Data1.Recordset .MoveNext If .EOF Then .MovePrevious MsgBox "You are on the last record", vbInformation, "Last Record" End If End With txtIDNo.Text = Data1.Recordset.Fields("IDNo")

txtName.Text = Data1.Recordset.Fields("Name") txtAge.Text = Data1.Recordset.Fields("Age") cboGender.Text = Data1.Recordset.Fields("Gender") txtAddress.Text = Data1.Recordset.Fields("Address") txtMobile.Text = Data1.Recordset.Fields("Mobile") txtEmail.Text = Data1.Recordset.Fields("Email") cboCourse.Text = Data1.Recordset.Fields("Course") cboMajor.Text = Data1.Recordset.Fields("Major") End Sub Private Sub cmdPrevious_Click() cmdLast.Enabled = True cmdNext.Enabled = True With Data1.Recordset .MovePrevious If .BOF Then .MoveNext MsgBox "You are on the first record", vbInformation, "First Record" End If End With txtIDNo.Text = Data1.Recordset.Fields("IDNo") txtName.Text = Data1.Recordset.Fields("Name") txtAge.Text = Data1.Recordset.Fields("Age") cboGender.Text = Data1.Recordset.Fields("Gender") txtAddress.Text = Data1.Recordset.Fields("Address") txtMobile.Text = Data1.Recordset.Fields("Mobile") txtEmail.Text = Data1.Recordset.Fields("Email") cboCourse.Text = Data1.Recordset.Fields("Course") cboMajor.Text = Data1.Recordset.Fields("Major") End Sub Private Sub cmdPrint_Click() ' MsgBox "This is your problem... add your own code here for your datareport and dataenvironment window", vbApplicationModal, "Message From Sir Reynan" ' MsgBox "Connection for report must be on app.path", vbApplicationModal, "Message From Sir Reynan" ' MsgBox "Good Luck and Happy Coding,,,!", vbApplicationModal, "Message From Sir Reynan"

End Sub Private Sub cmdSave_Click() If SaveAdd = True Then ' save the record for add command fra1.Visible = True fra1.Caption = "Saving Record..." cmdSave.Enabled = False cmdAdd.Enabled = False 'pass the Save for Add command function to tmrProgress '____________________________ tmrProgress.Enabled = True '---------------------------cmdAdd.Caption = "&Add" DisableButtons Else ' code startin from this line - specifies that SaveADD is not workin... ' and saving the record under edit command fra1.Visible = True fra1.Caption = "Saving Record..." 'pass the Save for Edit command function to tmrProgress '____________________________ tmrProgress.Enabled = True '--------------------------DisableButtons cmdSave.Enabled = False cmdEdit.Enabled = False cmdEdit.Caption = "&Edit" End If End Sub Private Sub Form_Load() ' call the location of the mdb file Data1.DatabaseName = App.Path & "\mdb\SRIS.mdb" Data1.RecordSource = "tblSRIS" Data1.Refresh

cmdSave.Enabled = False ' check database if it has no records If Data1.Recordset.RecordCount = 0 Then ' if it has no records , buttons such as delete, edit _ ' next,previous,first,last will be disabled On Error Resume Next Else txtIDNo.Text = Data1.Recordset.Fields("IDNo") txtName.Text = Data1.Recordset.Fields("Name") txtAge.Text = Data1.Recordset.Fields("Age") cboGender.Text = Data1.Recordset.Fields("Gender") txtAddress.Text = Data1.Recordset.Fields("Address") txtMobile.Text = Data1.Recordset.Fields("Mobile") txtEmail.Text = Data1.Recordset.Fields("Email") cboCourse.Text = Data1.Recordset.Fields("Course") cboMajor.Text = Data1.Recordset.Fields("Major") cmdEdit.Enabled = False End If ' Disable tmrProgress tmrProgress.Enabled = False fra1.Visible = False LockedInput lblDate = "Current Date :" & Format(Now, "Mmm/dd/yyyy") Ownership = "Preparatory Database Program for BSIT3 - Coded By:SirReynan" sksuIT = 0 End Sub Public Sub DisableButtons() ' a sub procedure to disable buttons below cmdNext.Enabled = False cmdPrevious.Enabled = False cmdFirst.Enabled = False cmdLast.Enabled = False cmdDelete.Enabled = False cmdPrint.Enabled = False

End Sub Public Sub EnableButtons() ' a sub procedure to enable buttons below cmdNext.Enabled = True cmdPrevious.Enabled = True cmdFirst.Enabled = True cmdLast.Enabled = True cmdDelete.Enabled = True cmdPrint.Enabled = True End Sub Private Sub mnuExit_Click() End End Sub Private Sub tmrProgress_Timer() If DeleteProgress = True Then pbr1.Value = pbr1.Value + 1 If pbr1.Value = 100 Then Data1.Recordset.Delete Data1.Recordset.MoveNext pbr1.Value = 0 fra1.Visible = False fra1.Caption = "" MsgBox "Your Record Has Been Sucessfully Deleted ", vbOKOnly, "Message" tmrProgress.Enabled = False 'newly added code to warn if there is 1 remaining record If Data1.Recordset.RecordCount = 1 Then MsgBox "You have only one record", vbCritical, "1 Record left!" Else txtIDNo.Text = "" txtName.Text = "" txtAge.Text = "" cboGender.Text = "" txtAddress.Text = "" txtMobile.Text = ""

txtEmail.Text = "" cboCourse.Text = "" cboMajor.Text = "" End If Data1.Refresh DeleteProgress = False End If Else ' tmrProgress acts as save command for add pbr1.Value = pbr1.Value + 1 If pbr1.Value = 100 Then 'execute adding of new records Data1.Recordset.AddNew Data1.Recordset.Fields("IDNo") = txtIDNo.Text Data1.Recordset.Fields("Name") = txtName.Text Data1.Recordset.Fields("Age") = txtAge.Text Data1.Recordset.Fields("Gender") = cboGender.Text Data1.Recordset.Fields("Address") = txtAddress.Text Data1.Recordset.Fields("Mobile") = txtMobile.Text Data1.Recordset.Fields("Email") = txtEmail.Text Data1.Recordset.Fields("Course") = cboCourse.Text Data1.Recordset.Fields("Major") = cboMajor.Text ' execute saving of newly added records Data1.Recordset.Update Data1.Refresh DBGrid1.Refresh txtIDNo.Text = Data1.Recordset.Fields("IDNo") txtName.Text = Data1.Recordset.Fields("Name") txtAge.Text = Data1.Recordset.Fields("Age") cboGender.Text = Data1.Recordset.Fields("Gender") txtAddress.Text = Data1.Recordset.Fields("Address") txtMobile.Text = Data1.Recordset.Fields("Mobile") txtEmail.Text = Data1.Recordset.Fields("Email")

cboCourse.Text = Data1.Recordset.Fields("Course") cboMajor.Text = Data1.Recordset.Fields("Major") pbr1.Value = 0 fra1.Visible = False fra1.Caption = "" If SaveAdd = True Then MsgBox "Record was Sucessfully Saved ", vbOKOnly, "Database Alert Message" Else MsgBox "Record was Sucessfully Modified ", vbOKOnly, "Database Alert Message" End If tmrProgress.Enabled = False LockedInput pbr1.Value = 0 fra1.Visible = False fra1.Caption = "" EnableButtons cmdAdd.Enabled = True cmdEdit.Enabled = True End If End If End Sub Private Sub tmrZeroCode_Timer() tmrZeroCode.Interval = 50 sksuIT = sksuIT + 1 staZeroCode.Panels(1).Text = Left(Ownership, sksuIT) If sksuIT = Len(Ownership) Then sksuIT = 1 tmrZeroCode.Interval = 2000 End If End Sub Private Sub txtAddress_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And txtAddress <> "" Then txtMobile.SetFocus SendKeys "{Home}+{End}"

End If End Sub Private Sub txtAge_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And txtAge <> "" Then cboGender.SetFocus SendKeys "{Home}+{End}" End If End Sub Private Sub txtEmail_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And txtEmail <> "" Then cboCourse.SetFocus End If End Sub Private Sub txtMobile_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And txtMobile <> "" Then txtEmail.SetFocus SendKeys "{Home}+{End}" End If End Sub Private Sub txtName_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And txtName <> "" Then txtAge.SetFocus SendKeys "{Home}+{End}" End If End Sub Private Sub txtSearch_Change() Dim searchkey searchkey = "[IDNo]like '" & txtSearch.Text & "*'" Data1.Recordset.FindFirst searchkey txtIDNo.Text = Data1.Recordset.Fields("IDNo") txtName.Text = Data1.Recordset.Fields("Name") txtAge.Text = Data1.Recordset.Fields("Age") cboGender.Text = Data1.Recordset.Fields("Gender") txtAddress.Text = Data1.Recordset.Fields("Address")

txtMobile.Text = Data1.Recordset.Fields("Mobile") txtEmail.Text = Data1.Recordset.Fields("Email") cboCourse.Text = Data1.Recordset.Fields("Course") cboMajor.Text = Data1.Recordset.Fields("Major") If Data1.Recordset.NoMatch = True Then MsgBox " Record not found!" End If End Sub Public Sub LockedInput() txtName.Locked = True txtAge.Locked = True cboGender.Locked = True txtAddress.Locked = True txtMobile.Locked = True cboCourse.Locked = True cboMajor.Locked = True End Sub Public Sub UnlockInput() txtName.Locked = False txtAge.Locked = False cboGender.Locked = False txtAddress.Locked = False txtMobile.Locked = False cboCourse.Locked = False cboMajor.Locked = False End Sub Private Sub txtSearch_Click() txtSearch.Text = "" End Sub

Sign up to vote on this title
UsefulNot useful