You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用QBFC判断MS Access与QuickBooks Pro 2017的连接是否成功?

解决QBFC连接QuickBooks Pro 2017的测试与自动启动问题

Hey there! I’ve dealt with this exact QBFC/QuickBooks connection headache before—let’s walk through how to test your connection and handle cases where QuickBooks isn’t running.

First, Understand the QBFC Connection Rule

QBFC requires a running instance of QuickBooks to establish a connection, but the good news is we can detect if QB is running, launch it programmatically, and retry the connection instead of just failing silently.

Test Connection & Handle QB Not Running: VBA Code Example

Here’s a reusable function you can add to your Access VBA module. It checks for an active QB instance, tries to connect, and even launches QB if it’s missing:

Option Explicit

' Reference required: QuickBooks FC 13.0 Object Library (match your QB 2017 version)
Function TestQBConnection(Optional qbPath As String = "C:\Program Files (x86)\Intuit\QuickBooks 2017\QBW32.exe") As Boolean
    Dim qbSession As QBSessionManager
    Dim connectionAttempts As Integer
    Const MAX_RETRIES As Integer = 3
    Const WAIT_SECONDS As Integer = 5
    
    On Error GoTo ConnectionError
    
    Set qbSession = New QBSessionManager
    
    ' Set up session details
    qbSession.OpenConnection2 "Your Access App Name", "Access-QB Integration"
    qbSession.BeginSession "", omDontCare
    
    ' If we get here, connection succeeded
    Debug.Print "QB Connection successful!"
    TestQBConnection = True
    
    ' Clean up
    qbSession.EndSession
    qbSession.CloseConnection
    Set qbSession = Nothing
    Exit Function

ConnectionError:
    Select Case Err.Number
        Case 3010 ' QuickBooks is not running
            Debug.Print "QuickBooks not found—launching now..."
            ' Launch QuickBooks
            Shell qbPath, vbNormalFocus
            ' Wait for QB to start up
            Application.Wait Now + TimeSerial(0, 0, WAIT_SECONDS)
            ' Retry connection
            connectionAttempts = connectionAttempts + 1
            If connectionAttempts < MAX_RETRIES Then
                Resume
            Else
                MsgBox "Failed to connect after launching QuickBooks. Please check if QB opened correctly."
                TestQBConnection = False
            End If
        Case 3000 ' Authorization required
            MsgBox "Access needs permission to connect to QuickBooks. Please open QuickBooks and grant access when prompted."
            TestQBConnection = False
        Case Else
            MsgBox "Connection error: " & Err.Description & " (Error Code: " & Err.Number & ")"
            TestQBConnection = False
    End Select
    
    ' Clean up on failure
    If Not qbSession Is Nothing Then
        If qbSession.IsOpenConnection Then qbSession.CloseConnection
        Set qbSession = Nothing
    End If
End Function

Key Notes for Success

  • Reference the Right QBFC Library: In your Access VBA editor, go to Tools > References and select the matching QuickBooks FC library (QB 2017 uses version 13.0).
  • Authorization: The first time you run this, QuickBooks will pop up an authorization window. Make sure to select "Yes, always allow access even if QuickBooks is not running" (this is critical for headless connections).
  • QB Path: Double-check the qbPath variable matches your actual QuickBooks 2017 installation path (it might differ if you used a custom install location).
  • Retry Logic: The wait time and retry count are adjustable—tweak WAIT_SECONDS and MAX_RETRIES if QB takes longer to launch on your system.

How to Use This

Call the function anywhere in your code before attempting QB operations:

If TestQBConnection() Then
    ' Proceed with your QBFC operations (e.g., fetching data, creating transactions)
Else
    ' Handle connection failure (e.g., alert user, exit process)
End If

内容的提问来源于stack exchange,提问作者DLee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:05:51