【发布时间】:2016-06-24 05:19:22
【问题描述】:
我遇到了 2013 Access 表单上的按钮问题。
高层:我在做一些监管表格,一个是服务请求,另一个是投诉请求。 每次服务呼叫都会打开服务请求,如果呼叫不是为了更换零件,它还会生成一般投诉请求。
我有一个表格“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
工作得很好。
【问题讨论】:
-
看起来它可以工作......我的意思是,它会产生[编译器] 投诉,对吗?
</dad-joke>...您确定突出显示的行是方法的签名吗?我第一次听到这种情况...... -
也就是说,所有这些
Set关键字一旦编译和运行就会导致运行时错误。Set用于分配对象引用,而您正在分配值。删除Set那里。 -
@Mat's Mug 我创建了一个新的“空白”按钮,称为 GenerateComplaint。我粘贴了第一个 If 语句,按钮按预期工作。该按钮是由 VBA 创建的
-
您是双击按钮并让 VBA 为您创建单击处理程序,还是您自己编写?
-
等等,它确实编译并运行了吗?有两种类型的错误: compile 错误使代码无法运行。 runtime 错误会在程序运行时炸毁程序。您的问题提到了一个 compile 错误,但是您说您让它显示一个消息框....您遇到的确切问题是什么?