我得到一个对象需要的错误,因为这是非常模糊的,我无法修复它。我想说:如果此记录的AssocID字段为空,请使用SQL语句等。如果不是,则显示MsgBox并转到下一条记录。这是我的代码。
Private Sub StartButton_Click()
DoCmd.SetWarnings False
Dim mySQL As String
GetID = Forms!frm_MainMenu!AssocIDBox
CurRecord = Forms!frm_EC_All![Loan#].Value
mySQL = "UPDATE tbl_Data SET tbl_Data.[AssocID] = " & GetID & " , tbl_Data.[tsStartAll] = Now WHERE tbl_Data.[Loan#] = " & CurRecord
'
'
'
If IsNull(tbl_Data.AssocID.Value) Then
DoCmd.RunSQL mySQL
DoCmd.SetWarnings True
Me.TimerActivatedLabel.visible = True
Me.Refresh
ClaimedMsg = MsgBox("Loan has been assigned to you.", vbOKOnly, "Loan Assigned")
If ClaimedMsg = vbOK Then
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE tbl_Data SET tbl_Data.[tsHaveDocs] = Now WHERE tbl_Data.[Loan#] = " & CurRecord
DoCmd.SetWarnings True
End If
Else
AlreadyAssignedMsg = MsgBox("Loan has already been assigned. Press OK to move to the next loan.", vbOKOnly, "Already Assigned!")
If AlreadyAssignedMsg = vbOKOnly Then
DoCmd.GoToRecord , , acNext
End If
End If
End Sub
If IsNull(etc)行发生错误。我看了很多其他的东西,但要么不适用,要么我真的不明白他们在谈论什么。我还是个初学者。谢谢!
答案 0 :(得分:2)
如果出于某些奇怪的原因,您没有tbl_Data.AssocID
字段作为表单中文本框的控件源,则可以执行以下操作:
...
' Declare a string variable and set it to the value of the field
' I concatenate an empty string to be sure to have not a null
Dim AssocID as string
AssocID = Dlookup("AssocID","tbl_Data","[Loan#] = " & CurRecord) & ""
' Test the string variable
If AssocID = "" Then
...