mysql - SQL 迁移后 VBA 脚本不再工作

标签 mysql vba ms-access

我最近将 Access 数据库(该数据库比我设计的更有知识)迁移到 MySQL,并将表链接回 Access 以用作前端。 几乎一切看起来都很棒。只有一种形式和一大块 VBA 代码似乎不起作用。有一个表单应该显示下拉菜单和控件,但在表单 View 中为空白。 The form in design view and form view表单附带的 VBA 代码是

Option Compare Database

Private Sub cmdPreviewPlate_Click()
'show user the new plate that is to be added to tblPCRsamples
On Error GoTo Err_cmdPreviewPlate_Click

'check whether boxes are blank
Dim bolBlank As Boolean
bolBlank = False

If IsNull(Me.Controls!cboChooseTemplatePlate) Then bolBlank = True
If IsNull(Me.Controls!cboChooseLocus) Then bolBlank = True
If IsNull(Me.Controls!txtEnterDate) Then bolBlank = True

If bolBlank = False Then
    'enable the Add button
    Me.Controls!cmdAddPlate.Enabled = True

    'generate the unique PCRplate from the template plate number and locus
    ' using the global variable GstrPCRPlateName so that the queries can add the plate name to both tables
    GstrPCRPlateName = Me.Controls!cboChooseTemplatePlate.Value & "_" & Me.Controls!cboChooseLocus

    'check: does this PCRplate already exist in tblPCRplates?
    Dim dbs As Database
    Dim rst As Recordset
    Dim bolDone As Boolean
    Dim bolNameExists As Boolean

    bolDone = False
    bolNameExists = False
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("tblPCRplates", dbOpenDynaset)

    rst.MoveFirst

    Do Until bolDone = True
        'does the new plate name automatically generated here = the value of PCRplate in the current record?
        If GstrPCRPlateName = rst![PCRPlate] Then
            bolNameExists = True
            bolDone = True
        End If

        rst.MoveNext

        If rst.EOF Then bolDone = True
    Loop

    'if the name already exists, make a new name by appending _ and the date
    If bolNameExists = True Then
        GstrPCRPlateName = GstrPCRPlateName & "_" & Me.Controls!txtEnterDate
    End If

    'set the value for the Locus
    GstrGetLocus = Me.Controls!cboChooseLocus

    'open the select query to show user what they're going to add to the PCR plates & samples tables
    Dim stDocName As String

    stDocName = "qryNewPCR_1SelectTemplatePlate"
    DoCmd.OpenQuery stDocName, acNormal, acReadOnly
Else
    'if user left fields blank (except page number, that can be blank), show an error message
    MsgBox "Choose/enter values for all the boxes"
End If

Exit_cmdPreviewPlate_Click:
    Exit Sub

Err_cmdPreviewPlate_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewPlate_Click

End Sub

Private Sub cmdAddPlate_Click()
'add this new plate to tblPCRplates and tblPCRsamples
On Error GoTo Err_cmdAddPlate_Click

'add the new plate to tblPCRplates
Dim stDocName As String
stDocName = "qryNewPCR_2AppendPlate"
DoCmd.OpenQuery stDocName, acNormal, acEdit

'run the query to append the samples to tblPCRsamples
stDocName = "qryNewPCR_3AppendSamples"
DoCmd.OpenQuery stDocName, acNormal, acEdit

'open frmPCRSamples to show the new plate has been added
stDocName = "frmPCRSamples"
DoCmd.OpenForm stDocName, acFormDS

Exit_cmdAddPlate_Click:
Exit Sub

Err_cmdAddPlate_Click:
MsgBox Err.Description
Resume Exit_cmdAddPlate_Click

End Sub

所以我的问题是,链接表是否会导致错误?我可以修改一些内容来表明它们是相互关联的吗?还是我找错了树?

感谢您的帮助。我对 VBA 一无所知(我的意思是,我可以跟着做),并且被指派去破坏,我的意思是……管理……这个数据库。这就是当你为生物学家提供计算机时会发生的情况;-) 即使只是一些好的资源也会有很大帮助。

最佳答案

当表单的 RecordSource 返回零记录并且表单或记录源不允许添加新记录时,就会发生这种情况。

检查记录源(表、查询或 SQL 字符串)并手动运行以查看是否返回记录。

关于mysql - SQL 迁移后 VBA 脚本不再工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33512646/

相关文章:

excel - VBA : Error 457 : this key is already associated with an element of collection 中的嵌套字典

c# - 如何在 C# 中通过 OLEDB 在 Access SQL 通配符查询中使用文字下划线?

ms-access - 如何在 Access 中引用控件的属性

mysql - 使用两个单独的 SQL 语句还是一个 SQL 语句与 JOIN 结合使用更快?

PHP/MySql HTML 表分组

excel - 如何使VBA函数 "VBA only"并将其作为UDF禁用

ms-access - (ColdFusion + Access) 数据库查询错误 "Too few parameters."

php - 如何在 PHP 中加入两个 MySQL 查询

java - Openshift MySQL UTF-8 编码

vba - 引用并打开外部 xlsm 库时强制退出