我遇到2013 Access窗體上的按鈕問題。Access 2013 VBA:編譯錯誤:未找到方法或數據成員
高層次:我正在制定一些規範形式,其中一個是服務請求,另一個是投訴請求。 服務請求在每個服務呼叫中打開,如果該呼叫不是用於零件更換,它還會生成一般性投訴請求。
我有一個表格「service_request_form」,它是技術人員填寫信息的地方。此表單上有一個按鈕,我想複製此服務表單中的所有數據並生成投訴請求記錄。從那裏關閉所有窗口,並根據我們的紙質記錄打印出2個自定義報告。
問題:我recieving「編譯錯誤:方法或數據成員未找到」上線
Private Sub GenerateComplaint_Click()
這是我在VBA第一次嘗試,所以請原諒,我不是一個開發商。
下面是VBA的按鈕:
Private Sub GenerateComplaint_Click()
If IsNull([txtAddress]) Or IsNull([txtCity]) Or IsNull([txtCompany]) Or IsNull([txtContact]) Or IsNull([txtDescription]) Or IsNull([txtEmail]) Or IsNull([txtPhoneNumber]) Or IsNull([txtPartNumberOrModel]) Or IsNull([txtSerialNumber]) Or IsNull([txtService Request Date]) Or IsNull([txtState]) Or IsNull([txtZip]) Then
MsgBox "Somethings not right"
Else
DoCmd.Save
Dim Prompt As Integer
Prompt = InputBox("Are you Sure you would like to create a Complaint Record? Type 1 for yes, 0 for No")
If Prompt = 1 Then
DoCmd.OpenForm "Complaint Request Form", , , , acFormAdd
Forms![Complaint Request Form].Form.Company = Me.txtCompany
Forms![Complaint Request Form].Form.Address = Me.txtAddress
Forms![Complaint Request Form].Form.Contact = Me.txtContact
Forms![Complaint Request Form].Form.Phone = Me.txtPhone
Forms![Complaint Request Form].Form.Email = Me.txtEmail
Forms![Complaint Request Form].Form.ProductNumber = Me.txtPartNumberOrModel
Forms![Complaint Request Form].Form.SerialNumber = Me.txtSerialNumber
Forms![Complaint Request Form].Form.City = Me.txtCity
Forms![Complaint Request Form].Form.State = Me.txtState
Forms![Complaint Request Form].Form.Zip = Me.txtZip
Forms![Complaint Request Form].Form.Description = Me.txtDescription
Forms![Complaint Request Form].Form.CusDescription = Me.txtCusDescription
Forms![Complaint Request Form].Form.ServiceRequestNumber = Me.ServiceRequestDate
Forms![Complaint Request Form].Form.ComplaintRequestDate = Me.txtService_Request_Date
Dim SN As Long
SN = Me.ServiceRequestNumber
DoCmd.Close acForm, "Complaint Request Form", acSaveYes
DoCmd.Close acForm, "Service_Request_sub", acSaveYes
'DoCmd.OpenTable "Complaint_Request", , acReadOnly
'DoCmd.Close acTable, "Complaint_Request", acSaveYes
DoCmd.OpenReport "ComplaintRequestReport", acViewPreview, , "[Complaint_Request]![ServiceRequestNum]=" & SN
'DoCmd.OpenReport "ServiceRequestReport", acViewPreview, , "[Service_Request]![ServiceRequestNumber]=" & SN
'Below line works, I think there is a data type issue, ServiceRequest!ServiceRequestNumber is an autonumber, Where complaintRequest!ServiceRequestNum is autonumber
DoCmd.OpenReport "ServiceRequestReport", acViewPreview, , "[Service_Request]![ServiceRequestNumber]=" & SN
'DoCmd.Close acForm, "Service_Request_sub"
ElseIf Promp = 0 Then
'do nothing'
Else
Prompt = InputBox("Are you Sure you would like to create a Complaint Record? Type 1 for yes, 0 for No")
End If
End If
End Sub
運行
Private Sub GenerateComplaint_Click()
If IsNull([txtAddress]) Or IsNull([txtCity]) Or IsNull([txtCompany]) Or IsNull([txtContact]) Or IsNull([txtDescription]) Or IsNull([txtEmail]) Or IsNull([txtPhoneNumber]) Or IsNull([txtPartNumberOrModel]) Or IsNull([txtSerialNumber]) Or IsNull([txtService Request Date]) Or IsNull([txtState]) Or IsNull([txtZip]) Then
MsgBox "Somethings not right"
End if
作品就好了。
看起來像它的工作......我的意思是,*生成[編譯]投訴*吧? ''...你確定*突出顯示的行是方法的*簽名*?我第一次聽到這種情況...... –
這就是說,所有這些'Set'關鍵字在編譯和運行後都會導致運行時錯誤。 'Set'用於分配*對象引用*,並且您正在分配*值*。在那裏刪除「設置」。 –
@馬特杯我創建了一個新的「空白」按鈕,稱爲GenerateComplaint。 我粘貼了第一個If語句,並且該按鈕按預期工作。該按鈕是由VBA創建的 –