hi im new to this first post!!
so im a second year computer science student and im having serious problems with an assignment due 2mro!! we were asked to make a program that would link to a database in access i linked it fine where im having the trouble is i cant delete records and my find student wont work and im having trouble generating a report!!! any help would be much appreciated!! vb6
heres the code!! sorry about the amount
Code:Private blnAddingNewRecord As Boolean Private blnValidationError As Boolean Private Sub CboField_Change() If CboField.Enabled Then CboRelOp.SetFocus End If End Sub Private Sub CboRelOp_Change() If CboRelOp.Enabled Then TxtCriteria.SetFocus End If End Sub Private Sub CmdCancelFind_Click() TxtStudentID.Enabled = True TxtStudentName.Enabled = True TxtCourse.Enabled = True TxtRentPaid.Enabled = True TxtRoomType.Enabled = True CmdMoveFirst.Enabled = True CmdMoveLast.Enabled = True CmdMovePrevious.Enabled = True CmdMoveNext.Enabled = True CmdDeleteRecord.Enabled = True CmdNewRecord.Enabled = True CmdUndo.Enabled = True CmdSaveRecord.Enabled = True CmdCancelNew.Enabled = True CmdFind.Enabled = True CmdCancelFind.Enabled = False CmdGo.Enabled = True CboField.Enabled = False CboRelOp.Enabled = False TxtCriteria.Enabled = False End Sub Private Sub cmdCancelNew_Click() 'cancel the AddNew DatStudents.Recordset.CancelUpdate DatStudents.UpdateControls 'enable & disable the appropriate buttons CmdSaveRecord.Enabled = False CmdCancelNew.Enabled = False CmdMoveFirst.Enabled = True CmdMoveLast.Enabled = True CmdMovePrevious.Enabled = True CmdMoveNext.Enabled = True CmdDeleteRecord.Enabled = True CmdNewRecord.Enabled = True CmdUndo.Enabled = True blnAddingNewRecord = False End Sub Private Sub CmdDeleteRecord_Click() Dim StudentId As Integer Dim StudentName As String Dim Course As String Dim Paid As Currency Dim RoomType1 As String BookMark = DatStudents.Recordset.BookMark Paid = "RENT_PAID" StudentName = "STUDENT_NAME" StudentId = "STUDENT ID" Course = "COURSE" RoomType1 = "ROOM TYPE" On Error GoTo Delete_Error If MsgBox("Are you sure you want to delete this record?", _ vbQuestion + vbYesNo + vbDefaultButton2, _ "Confirm") = vbNo Then Exit Sub End If 'delete the current record DatStudents.Recordset.Delete 'move to a valid record CmdMoveNext_Click Exit Sub Delete_Error: MsgBox "This record cannot be deleted. Error code = " _ & Err.Number & vbCrLf & Err.Description, _ vbCritical, "Cannot Delete" End Sub Private Sub CmdFindstudent_Click() Dim StrQueryString As String, strStudentNumber As String strStudentNumber = InputBox("What is the students ID number") StrQueryString = "STUDENT ID = " & strStudentNumber If Trim$(strStudentNumber) = "" Then MsgBox "Student ID must be entered" TxtStudentID.SetFocus GoTo CancelValidateAction End If List1.Clear DatStudents.Recordset.FindFirst StrQueryString If DatStudents.Recordset.NoMatch Then MsgBox "No match for this student ID Number", vbExclamation End If blnValidationError = False Exit Sub CancelValidateAction: blnValidationError = True Action = vbDataActionCancel Save = False End Sub Private Sub CmdMoveFirst_Click() DatStudents.Recordset.MoveFirst StrBookMark = DatStudents.Recordset.BookMark End Sub Private Sub CmdMoveLast_Click() DatStudents.Recordset.MoveLast StrBookMark = DatStudents.Recordset.BookMark End Sub Private Sub CmdMoveNext_Click() DatStudents.Recordset.MoveNext If DatStudents.Recordset.EOF = True Then DatStudents.Recordset.MoveFirst End If StrBookMark = DatStudents.Recordset.BookMark End Sub Private Sub CmdMovePrevious_Click() DatStudents.Recordset.MovePrevious If DatStudents.Recordset.BOF = True Then DatStudents.Recordset.MoveLast End If StrBookMark = DatStudents.Recordset.BookMark End Sub Private Sub CmdNewRecord_Click() DatStudents.Recordset.AddNew CmdSaveRecord.Enabled = True CmdCancelNew.Enabled = True CmdMoveFirst.Enabled = False CmdMoveLast.Enabled = False CmdMovePrevious.Enabled = False CmdMoveNext.Enabled = False CmdDeleteRecord.Enabled = False CmdNewRecord.Enabled = False CmdUndo.Enabled = False blnAddingNewRecord = True End Sub Private Sub CmdSaveRecord_Click() DatStudents.Recordset.Update If blnValidationError Then Exit Sub ' make the new record the current record DatStudents.Recordset.BookMark _ = DatStudents.Recordset.LastModified CmdSaveRecord.Enabled = True CmdCancelNew.Enabled = False CmdMoveFirst.Enabled = True CmdMoveLast.Enabled = True CmdMovePrevious.Enabled = True CmdMoveNext.Enabled = True CmdDeleteRecord.Enabled = True CmdNewRecord.Enabled = True CmdUndo.Enabled = True blnAddingNewRecord = False End Sub Private Sub CmdRent_Click() Dim StrQueryString As String Dim BookMark As Variant BookMark = DatStudents.Recordset.BookMark StrQueryString = "RENT_PAID < 1000" List1.Clear DatStudents.Recordset.FindFirst StrQueryString Do Until DatStudents.Recordset.NoMatch List1.AddItem DatStudents.Recordset("STUDENT_NAME") & _ " " & Format(DatStudents.Recordset("RENT_PAID"), _ "Currency") DatStudents.Recordset.FindNext StrQueryString Loop DatStudents.Recordset.BookMark = BookMark End Sub Private Sub CmdUndo_Click() DatStudents.UpdateControls End Sub Private Sub Command1_Click() Dim StQueryString As String Dim BookMark As Variant BookMark = DatStudents.Recordset.BookMark StQueryString = "number of people in appartment =< 4" List2.Clear DatStudents.Recordset.FindFirst StQueryString Do Until DatStudents.Recordset.NoMatch List2.AddItem DatStudents.Recordset("type of room") & _ " " & Format(DatStudents.Recordset)("number of people in appartment") DatAppertments.Recordset.FindNext StQueryString Loop DatAppertments.Recordset.BookMark = BookMark End Sub Private Sub DatAppertments_Validate(Action As Integer, Save As Integer) If Action = vbDataActionBookmark Then Exit Sub If Action = vbDataActionDelete Then Exit Sub 'check to see if a valid student id is entered: If TxtStudentID.DataChanged Or blnAddingNewRecord Then If Trim$(TxtStudentID) = "" Or 0 Then MsgBox "Student ID must be entered" TxtStudentID.SetFocus GoTo CancelValidateAction End If End If If TxtStudentName.DataChanged Or blnAddingNewRecord Then If Trim$(TxtStudentName) = "" Then MsgBox "Student Name must be entered" TxtStudentName.SetFocus GoTo CancelValidateAction End If End If If TxtCourse.DataChanged Or blnAddingNewRecord Then If Trim$(TxtCourse) = "" Then MsgBox "Course Name must be entered" TxtCourse.SetFocus GoTo CancelValidateAction End If End If If TxtRentPaid.DataChanged Or blnAddingNewRecord Then If Val(TxtRentPaid) = 0 Then MsgBox "50% Rent must be paid" TxtRentPaid.SetFocus GoTo CancelValidateAction End If End If If TxtRoomType.DataChanged Or blnAddingNewRecord Then If Trim$(TxtRoomType) = "" Then MsgBox "Room Type must be specified" TxtRoomType.SetFocus GoTo CancelValidateAction End If End If blnValidationError = False Exit Sub CancelValidateAction: blnValidationError = True Action = vbDataActionCancel Save = False End Sub





Reply With Quote