SQL迁移后,VBA脚本不再有效

时间:2015-11-04 02:20:27

标签: mysql vba ms-access

我最近将一个Access数据库(比我设计的知识更多的人)迁移到MySQL,并将表连接回Access以用作前端。 几乎一切看起来都很棒。只有一种形式和大块的VBA代码似乎无法运作。有一个表单应该显示下拉菜单和控件,但在窗体视图中是空白的。 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一无所知(我的意思是,我可以跟随)并且已经被要求销毁,我的意思是......管理员......这个数据库。当你给生物学家的计算机时会发生这种情况;-)即使只是一些好的资源也会有很大的帮助。

1 个答案:

答案 0 :(得分:1)

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

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