嗨,我需要帮助解决我在代码中遇到的这个错误。变量没有定义,在我定义变量后,它会抛出另一个错误,说找不到方法或数据成员,它总是突出显示DataEnvironment1.commands.am正在使用日历访问我的报告。可能出了什么问题,请帮忙。
这是我的代码:
Private Sub cmdOK_Click()
On Error GoTo e
frmDate = txtdate1.Text
endDate = txtdate2.Text
DataEnvironment1.Commands("InpatientMaintenanceMaster").Parameters(0) = txtdate1
DataEnvironment1.Commands("InpatientMaintenanceMaster").Parameters(1) = txtdate2
With RptInpatientMaster
.Sections("Section2").Controls("lblDate1").Caption = txtdate1.Text
.Sections("Section2").Controls("lblDate2").Caption = txtdate2.Text
.Show
End With
DataEnvironment1.rsInpatientMaintenanceMaster.Close
Unload Me
Exit Sub
e:
If Err.Number <> 3704 Then
MsgBox Err.Description, vbCritical
End If
End Sub
请删除此行:
DataEnvironment1.Commands("InpatientMaintenanceMaster").Parameters(0) = txtdate1
相反,用这个替换它,然后告诉我们哪一行显示为您的错误:
Dim dataEnv As Object
Set dataEnv = DataEnvironment1
Dim cmd As Object
Set cmd = dataEnv.Commands("InpatientMaintenanceMaster")
Dim dateString As String
dateString = txtdate1.Text 'assuming this is truly a textbox control?
cmd.Parameters(0) = dateString 'should really be using frmDate instead
通过将其拆分,它应该会缩小您所缺少的内容。