【发布时间】:2017-01-06 02:03:16
【问题描述】:
我对编码非常非常陌生,所以请放轻松!
我遵循了一个教程,允许我从主表单的组合框中填充子表单。我只是想知道我可以改变什么来确保我不会一直收到这个错误。当一个模块被添加到学生时,如果我想或继续不添加任何其他内容,我希望表单允许我退出它,但是当我尝试离开表单时,我收到一条错误消息,让我选择另一个模块。我怎样才能阻止这种情况发生?
请看下面的代码和截图:
Form appearance when I have selected a student and module ready to add
表单 VBA 代码,请注意我也有 LinkMaster 作为 studentcombo 和 LinkChild 作为 StudentID 的子表单
'combo box for StudentID updates all other student detail text boxes.
Private Sub studentcombo_AfterUpdate()
programmetb = DLookup("ProgrammeID", "tblStudent", "[StudentID]=studentcombo")
firstnametb = DLookup("FirstName", "tblStudent", "[StudentID]=studentcombo")
surnametb = DLookup("Surname", "tblStudent", "[StudentID]=studentcombo")
SNtb = DLookup("StudentNumber", "tblStudent", "[StudentID]=studentcombo")
StudentIDhidden = studentcombo
End Sub
'combo box for ModuleCode updates all other module detail text boxes.
Private Sub modulecodecombo_AfterUpdate()
modulenametb = DLookup("ModuleName", "tblModule", "[ModuleCode]=modulecodecombo")
creditstb = DLookup("Credits", "tblModule", "[ModuleCode]=modulecodecombo")
semester1tb = DLookup("Semester_1", "tblModule", "[ModuleCode]=modulecodecombo")
semester2tb = DLookup("Semester_2", "tblModule", "[ModuleCode]=modulecodecombo")
prereqtb = DLookup("Pre_requisites", "tblModule", "[ModuleCode]=modulecodecombo")
ModuleCodehidden = modulecodecombo
End Sub
Private Sub AddModuleBut_Click()
'Verification that studentID is selected.
If IsNull(studentcombo) Then
MsgBox "Please select student", , "Required"
studentcombo.SetFocus
Exit Sub
End If
'Verification that modulecode is selected.
If IsNull(modulecodecombo) Then
MsgBox "Please select a course", , "Required"
modulecodecombo.SetFocus
Exit Sub
'Else create a record in the subform using the combo box data.
Else
DoCmd.GoToRecord , , acNewRec
StudentIDhidden = studentcombo
End If
End Sub
提前致谢! ^^
【问题讨论】: