我一直在處理以下代碼,以便當用戶單擊按鈕保存並轉到新記錄時,Access會查找設置位置使用的最高客戶端ID,然後向其添加1。在保存記錄並轉移到新記錄之前。雖然通過其他錯誤工作,但我無法通過這條線上所需的錯誤對象。 「Me.ClientID = IIf(DMax(」[ClientID]「,」tClientinfo「,」[CorpsName] =「&」'defaultcorps'「)Null,0,DMax(」[ClientID]「,」tClientinfo「 [CorpsName] =「&」'defaultcorps'「))+ 1」運行時錯誤424對象需要
我越看越類似的問題,我對代碼有什麼問題感到困惑。預先感謝您的任何建議大衛
Private Sub Save_Record_Click()
'declare variables for default values
Dim defaultinterviewr As String
Dim defaultcorps As String
'Variables get their values
defaultinterviewr = Me.Interviewer.Value
defaultcorps = Me.Corps.Value
'Check to see if ClientID field is Blank.
If IsNull(Me.ClientID) Then
'Check that Corps field is filled in
If IsNull(Me.Corps) Then
MsgBox "Corps must be entered before saving record.", vbOKOnly
Me.Corps.SetFocus
'set client id base on corps by finding the highest id and adding 1 to that number
Else
Me.ClientID = IIf(DMax("[ClientID]", "tClientinfo", "[CorpsName]=" & "'defaultcorps'") Is Null, 0, DMax("[ClientID]", "tClientinfo", "[CorpsName]=" & "'defaultcorps'")) + 1
End If
End If
MsgBox "Done", vbOKOnly
'save record
'DoCmd.RunCommand acCmdSaveRecord
'Me.stateidnum1 = ""
'open new record
'DoCmd.GoToRecord , , acNewRec
'set field default value
'Me.Interviewer.Value = defaultinterviewr
'Me.Corps.Value = defaultcorps
'Me.Child_Subform.Form.AllowAdditions = True
End Sub
Anthony謝謝你指出DMAX功能不工作,這是我的前兆。雖然我無法弄清field,table和critera的正確語法。 – DavidR
查看我上面更新的答案。我錯過了defaultcorps是一個變量而不是數據值的事實。此更新應該會產生您正在尋找的內容。 –
安東尼謝謝你的代碼作品。 – DavidR