Access 2013 VBA:Complie错误:找不到方法或数据成员 [英] Access 2013 VBA: Complie error: Method or data member not found

查看:209
本文介绍了Access 2013 VBA:Complie错误:找不到方法或数据成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在2013 Access表单上的按钮有问题.

I am having an issue with a button on a 2013 Access form.

高级别:我正在制定一些监管表格,一种是服务请求,另一种是投诉请求. 在每个服务呼叫中都会打开一个服务请求,如果该呼叫不是要更换零件,它还会生成一个一般的投诉请求.

High level: I am making some regulatory forms, 1 is a service Request, the other is a complaint request. A service request is opened on every service call, if the call is not for a part replacement, it also generates a general complaint request.

我有一个表格"service_request_form",技术人员可以在该表格中填写信息.该表格上有一个按钮,我想从该服务表格中复制所有数据并生成投诉请求记录.从那里关闭所有窗口,并根据我们的纸质记录打印出2个自定义报告.

I have a form "service_request_form" which is where techs fill out the info. There is a button on this form which i would like to copy all data from this service form and generate a complaint request record. From there it closes all windows, and prints out 2 custom reports based on our paper records.

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

Issue: I am recieving "Compile Error: Method or data member not found" on line

Private Sub GenerateComplaint_Click()

这是我第一次尝试vba,请耐心等待,我不是开发人员.

This is my first attempt at vba, so please bear with me, I am not a developer.

以下是按钮的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

工作正常.

推荐答案

供以后参考:

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

Put Option Explicit at the top of each module.
It enforces variable declaration and reports undeclared or misspelled variables/constants at compile time.

要在新模块中自动启用此功能,请设置需要变量声明选项.

To have this automatically in new modules, set the Require Variable Declaration option in the VBA Editor.

并阅读:调试VBA代码

这篇关于Access 2013 VBA:Complie错误:找不到方法或数据成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆