Beruflich Dokumente
Kultur Dokumente
107
108 Private Sub cmdSave_Click()
109 'Call SaveData function
110 If SaveData() = False Then
111 'Errors, so do not run rest of procedure code
112 Exit Sub
113 End If
114 'Reset objects on form from Add mode to normal mode
115 Me.cmdAdd.Visible = True
116 Me.cmdSave.Visible = False
117 Me.cmdCancel.Visible = False
118 'Increment end of file counter
119 LastStud = LastStud + 1
120 'Move focus to last (new) record
121 OnStud = LastStud
122 'Add new item to combo box
123 Me.cboStudentNo.AddItem UCase(Trim(Student.Surname)) & " " & Student.Forename & Space(20) & LastStud
124 'Select new item in combo box
125 Me.cboStudentNo.Text = UCase(Trim(Student.Surname)) & " " & Student.Forename & Space(20) & LastStud
126 'Set combo box visible again
127 Me.cboStudentNo.Visible = True
128 'Reset data change flag to false
129 DataChanged = False
130 Call cboStudentNo_Click
131 End Sub
132
133 Private Function SaveData() As Boolean
134 Dim N As Byte
135 'Clear previous error message
136 For N = 0 To 7
137 Me.lblError(N).Visible = False
138 Next N
139
140 'Validate fields
141 '===============
142 'StudID
143 If IsStudID(Me.txtStudID) = False Then
144 Me.txtStudID.SetFocus
145 SaveData = False
146 Me.lblError(0).Visible = True
147 Exit Function
148 End If
149 'Surname
150 If IsName(Me.txtSurname) = False Then
151 Me.txtSurname.SetFocus
152 SaveData = False
153 Me.lblError(1).Visible = True
154 Exit Function
155 End If
156 'Forename
157 If IsName(Me.txtForename) = False Then
158 Me.txtForename.SetFocus
159 SaveData = False
160 Me.lblError(2).Visible = True
161 Exit Function
162 End If
163 'Street
164 If Len(Trim(Me.txtStreet)) = 0 Then
165 Me.txtStreet.SetFocus
166 SaveData = False
167 Me.lblError(3).Visible = True
168 Exit Function
169 End If
170 'Distict
171 If IsWords(txtDistrict) = False And Len(Trim(InString)) > 0 Then
172 Me.txtForename.SetFocus
173 SaveData = False
174 Me.lblError(4).Visible = True
175 Exit Function
176 End If
177 'Town
178 If IsWords(Me.txtTown) = False Then
179 Me.txtTown.SetFocus
180 SaveData = False
181 Me.lblError(5).Visible = True
182 Exit Function
183 End If
184 'County
185 Me.txtCounty = Trim(txtCounty)
186 If IsName(Me.txtCounty) = False Then
187 Me.txtCounty.SetFocus
188 SaveData = False
189 Me.lblError(6).Visible = True
190 Exit Function
191 End If
192 'Postcode
193 If IsPostCode(Me.txtPostcode) = False Then
194 Me.txtPostcode.SetFocus
195 SaveData = False
196 Me.lblError(7).Visible = True
197 Exit Function
198 End If
199 SaveData = True
200
201 'If it gets here then it is valid - so save record
202
203 'Copy form values into record
204 With Student
205 .StudNo = OnStud
206 .StudID = Me.txtStudID
207 .Surname = Me.txtSurname
208 .Forename = Me.txtForename
209 .Street = Me.txtStreet
210 .District = Me.txtDistrict
211 .Town = Me.txtTown
212 .County = Me.txtCounty
frmEditStudent.frm (06/02/2011) Page 3