如何在MS Access vba中对分数和成绩进行硬编码,如何将值放在表中并从表中访问它们?这样,当得分范围发生变化时,我不必回到vba代码并更新它。我只是更新表格中的值,代码只会提取分数范围并在字段上分配正确的等级。请帮忙......
Private Sub MarkScored_Exit(Cancel As Integer)
Dim mScore As Integer
mScore = Nz(Forms![frmAssessmentDetails]![subfrmAcademicAssessment]![MarkScored])
If mScore >= 0 And mScore <= 10 Then
Forms![frmAssessmentDetails]![subfrmAcademicAssessment]![cboGradeCode] = "VLA"
ElseIf mScore > 10 And mScore <= 15 Then
Forms![frmAssessmentDetails]![subfrmAcademicAssessment]![cboGradeCode] = "LA"
ElseIf mScore > 15 And mScore <= 20 Then
Forms![frmAssessmentDetails]![subfrmAcademicAssessment]![cboGradeCode] = "S"
ElseIf mScore > 20 And mScore <= 25 Then
Forms![frmAssessmentDetails]![subfrmAcademicAssessment]![cboGradeCode] = "HA"
ElseIf mScore > 25 And mScore <= 30 Then
Forms![frmAssessmentDetails]![subfrmAcademicAssessment]![cboGradeCode] = "VHA"
Else
MsgBox "Please enter valid mark for Score between 0 and 30", vbOKCancel, "Invalid Number"
End If
End Sub
答案 0 :(得分:2)
我建议在数据库中创建一个新表,比如
|ID| gradeCode | fromScore | toScore|
0 VLA 0 10
1 LA 11 15
2 S 16 20
然后在代码中查询
Select gradeCode from <gradeCodeTableName> where mScore between fromScore and toScore
编辑:正如Gustav建议的那样,在不浪费资源的情况下更好的方法是创建表格
|ID| gradeCode | fromScore |
0 VLA 0
1 LA 11
2 S 16
并查询
Select Top 1 gradeCode From <gradeCodeTableName> Where mScore >= fromScore Order By fromScore Desc
您将保存1列数据