问候Stackoverflow,
我正在编写我们用于大学的材料数据库,并且我正在尝试为输入到ms-access 2016数据库系统的材料实施5星评级系统。我完成了大部分的基础工作,但我遇到了编码错误。
我认为它可能与我试图添加到我自己的程序中的2007版本的示例中的编码脚本有关。我有点像设计和编码的初学者,所以原谅任何失误。
这就是我所拥有的:
有一个带有以下代码的vba模块:
Option Compare Database
Option Explicit
Public Function SetRating(frm As Object, ctl As Access.Control)
'Code: by Daniel van den Berg
On Error GoTo Err_handler
Dim strStar As String
Dim strBlank As String
' set path to picture accordingly
strStar = "C:\Users\jason\Pictures\yellow_sm.png"
strBlank = "C:\Users\jason\Pictures\blank_sm.png"
Select Case ctl.Value
Case Is = 0
frm.imgSt1.Picture = strBlank
frm.imgSt2.Picture = strBlank
frm.imgSt3.Picture = strBlank
frm.imgSt4.Picture = strBlank
frm.imgSt5.Picture = strBlank
Case Is = 1
frm.imgSt1.Picture = strStar
frm.imgSt2.Picture = strBlank
frm.imgSt3.Picture = strBlank
frm.imgSt4.Picture = strBlank
frm.imgSt5.Picture = strBlank
Case Is = 2
frm.imgSt1.Picture = strStar
frm.imgSt2.Picture = strStar
frm.imgSt3.Picture = strBlank
frm.imgSt4.Picture = strBlank
frm.imgSt5.Picture = strBlank
Case Is = 3
frm.imgSt1.Picture = strStar
frm.imgSt2.Picture = strStar
frm.imgSt3.Picture = strStar
frm.imgSt4.Picture = strBlank
frm.imgSt5.Picture = strBlank
Case Is = 4
frm.imgSt1.Picture = strStar
frm.imgSt2.Picture = strStar
frm.imgSt3.Picture = strStar
frm.imgSt4.Picture = strStar
frm.imgSt5.Picture = strBlank
Case Is = 5
frm.imgSt1.Picture = strStar
frm.imgSt2.Picture = strStar
frm.imgSt3.Picture = strStar
frm.imgSt4.Picture = strStar
frm.imgSt5.Picture = strStar
End Select
Exit_err:
Exit Function
Err_handler:
MsgBox Err.Number & " " & Err.Description
Resume Exit_err:
End Function
在表单中,我将以下内容作为事件过程
Private Sub cmdNoRating_Click()
NoRating Me.mRating
End Sub
Private Sub Form_Current()
SetRating Form_Material Details, Me.mRating
End Sub
Private Sub imgSt1_Click()
SetRatingClick Me.imgSt1, Me.mRating
End Sub
Private Sub imgSt2_Click()
SetRatingClick Me.imgSt2, Me.mRating
End Sub
Private Sub imgSt3_Click()
SetRatingClick Me.imgSt3, Me.mRating
End Sub
Private Sub imgSt4_Click()
SetRatingClick Me.imgSt4, Me.mRating
End Sub
Private Sub imgSt5_Click()
SetRatingClick Me.imgSt5, Me.mRating
End Sub
我的代码有什么问题吗?
答案 0 :(得分:0)
您向SetRating
事件中的Form_Current
函数传递了错误数量的参数,并且还使用了未设置的变量。
尝试将其替换为:
Private Sub Form_Current()
SetRating Me.Form, Me.mRating
End Sub
另外,请注意,只是在生产环境中无法完全理解的复制粘贴VBA存在安全隐患。尝试阅读您的代码。
请注意,删除它可能会导致在刷新表单或切换记录时不加载评级。