Private Sub cmdSave_Click()
If NoEntry = False Then 'test if data has been entered
'take data from the screen and save to the recordset
'update mrsStudents
Dim pstSaveMsg As String 'the message to be displayed to the user
Dim pinButtons As Integer 'corresponds to type of buttons in the message eg: 4 = vbYesNo
Dim pstFindCriteria As String 'criteria to find a record
Dim pinResponse As Integer 'corresponds to the button cliked in the message
Dim prsEventNum As New ADODB.Recordset 'to load all Student IDs in tblStudents
Dim pstEventNumSQL As String 'statement to load prsAllID
'Dim pinResponse As Integer
With mrsEvents
If mstMode = "Add" Then
'add new record to the recordset and make it active
.AddNew
'create message to be displayed to the user
pstSaveMsg = "The added record is going to be saved. " & _
"Do you want to add new one?"
pinButtons = 4 '4 = vbYesNo
ElseIf mstMode = "Edit" Then
'make sure the pointer is at the record that is being edited
pstFindCriteria = "EventNum = '" & mstEventNum & "'"
.MoveFirst
.Find pstFindCriteria
pstSaveMsg = " The edited record is going to be saved."
pinButtons = 0 '0 = vbOkOnly
End If
'create sql statement
pstEventNumSQL = "SELECT max(tblEvents.EventNum) + 1 as maxEventNum " & _
"FROM tblEvents"
'open the recordset
prsEventNum.Open pstEventNumSQL, gcnGiftRegistry, adOpenStatic, adLockOptimistic, adCmdText
'MsgBox prsEventNum!maxEventNum
'read data from the form and write to the recordset - not all fields are required
!eventNum = prsEventNum!maxEventNum
!LastName = txtLastName.Text
!FirstName = txtFirstName.Text
!Street = txtStreet.Text
!Suburb = txtSuburb.Text
!PostCode = txtPostCode.Text
!Phone = txtPhone.Text
!EventDate = txtEventDate.Text
!EventType = txtEventType.Text
If mstMode = "Add" Then
End If
.Update
'get the updated recordset into mrsStudents
'.Requery
'Unload frmEvent
'Load frmEventGiftList
Hide
frmEventGiftList.Show 1
End With
'show the appropriate message to the user
'pinResponse = MsgBox(pstSaveMsg, pinButtons, "Record Saved")
If pinResponse = 6 Then 'the user wants to add new record
Call SetActiveControls
Else 'the user's finished adding/editing a record
If gstEventNum <> "" Then
'the form was opened from frmStudentBooks
'return to frmStudentBooks
Unload Me
Else
'find the edithed/added record and display it
pstFindCriteria = "EventNum = '" & txtEventNum.Text & "'"
mrsEvents.MoveFirst
mrsEvents.Find pstFindCriteria
Call DisplayData
'set the form to the "View" mode
mstMode = "View"
lblheadings.Caption = "Events"
Call ShowCommands 'show function and navigation commands
Call SetInactiveControls 'lock textboxes
End If
End If
End If
End Sub