访问VBA传递参数vbs文件

时间:2014-03-26 19:09:39

标签: vba access-vba

我正在创建一个应该打开访问权限的.vbs文件,并在内部访问表单调用"发布详细信息",但是传递参数,这意味着如果我在我的"问题和#34; table为每个文件创建一个vbs文件,单击该文件时应打开正确的记录(对于表中的每个记录将是一个ID)。到目前为止,它是打开访问权限并打开表单(问题详细信息),但它是空白的。我错过了什么?帮助,在这里变得疯狂...检查下面的代码。这里奇怪的是,如果我再次双击它将刷新并打开正确的记录而不再打开窗口..我怎么能解决这个问题?我不想做两次:)

Public Sub sendMRBmail(mrbid)
    DoCmd.OpenForm "Issue Details", , , "[ID] = " & mrbid
    End Sub

    Private Sub Create_Click()
    On Error GoTo Err_Command48_Click
    Dim snid As Integer
    snid = Me.ID
    Dim filename As String
    filename = "S:\Quality Control\vbs\QC" & snid & ".vbs" 
    Dim proc As String
    proc = Chr(34) & "sendMRBmail" & Chr(34)

    Dim strList As String

    strList = "On Error Resume Next" & vbNewLine
    strList = strList & "dim accessApp" & vbNewLine
    strList = strList & "set accessApp = createObject(" & Chr(34) & "Access.Application" & Chr  (34)")" & vbNewLine
    strList = strList & "accessApp.OpenCurrentDataBase(" & Chr(34) & "S:\Quality Control\Quality     DB\Quality Database.accdb" & Chr(34) & ")" & vbNewLine
    strList = strList & "accessApp.Run " & proc & "," & Chr(34) & snid & Chr(34) & vbNewLine
    strList = strList & "set accessApp = nothing" & vbNewLine
    Open filename For Output As #1
    Print #1, strList
   Close #1

   Err_Command48_Click:

   If Err.Number <> 0 Then
    MsgBox "Email Error #: " & Err.Number & ", " & "Description: " & Err.Description
    Exit Sub
End If
End Sub

这是创建的vbs文件中的内容

On Error Resume Next
dim accessApp
set accessApp = GetObject("S:\Quality Control\Quality    DB\Quality Database.accdb")
accessApp.Run"sendMRBmail","231"
set accessApp = nothing

1 个答案:

答案 0 :(得分:0)

感谢所有投入,我已经找到了答案。我在DoCmd的末尾添加了acFormEdit并且它工作正常,请查看以下内容:

DoCmd.OpenForm "Issue Details", , , "[ID] = " & mrbid, acFormEdit