我是VBA和Access的新手,我正在尝试隐藏基于tsql数据库中的位字段的按钮,当我评论执行查询的代码行时,访问表单加载正常,当我取消它,它崩溃..请帮忙!我不确定我做错了什么。
Private Sub Form_Activate()
DoCmd.Maximize
Dim RecordSt As Recordset
Dim dbase As Database
Dim query As String
query = "select * from tblsetup;"
Set RecordSt = dbase.OpenRecordset(query) 'Line of code that crashes page
'If RecordSt.Fields("ValidateChecks").Value = 0 Then
'cmdValidate.Visible = False
'Else
'cmdValidate.Visible = True
'End If
End Sub
答案 0 :(得分:4)
您尚未将dbase设置为等于任何内容。如果表是链接表,则希望dbase等于CurrentDB:
Set dbase = CurrentDB
将其置于“Set Recordst”声明
之上