Access 2013 VBA:编译错误:找不到方法或数据成员

时间:2016-06-23 18:50:49

标签: vba ms-access

我在2013 Access表单上遇到按钮问题。

高级别:我正在制定一些监管表格,1是服务请求,另一个是投诉请求。 每次服务呼叫都会打开服务请求,如果呼叫不是部件更换,它还会生成一般投诉请求。

我有一个表单" service_request_form"这是技术人员填写信息的地方。此表单上有一个按钮,我想从此服务表单中复制所有数据并生成投诉请求记录。从那里它关闭所有窗口,并根据我们的纸质记录打印出2份自定义报告。

问题:我正在接收"编译错误:未找到方法或数据成员"在线

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

工作得很好。

2 个答案:

答案 0 :(得分:0)

Forms![Complaint Request Form].Form.Phone = Me.txtPhone

应该是

Forms![Complaint Request Form].Form.Phone = Me.txtPhoneNumber

抱歉浪费你的时间。

答案 1 :(得分:0)

供将来参考:

Option Explicit放在每个模块的顶部。
它强制执行变量声明,并在编译时报告未声明或拼写错误的变量/常量。

要在新模块中自动执行此操作,请在VBA编辑器中设置Require Variable Declaration选项。

并阅读:Debugging VBA Code