Access拉取扫描时设置佳能打印机默认进纸器及代码报错求助
解决WIA设置佳能扫描器顶部进纸器时的参数错误问题
问题分析
错误代码 -2147024809 表示参数不正确,核心原因是WIA属性设置的目标对象、时机或取值不符合设备要求。你使用的3088是WIA标准属性WIA_DPS_DOCUMENT_HANDLING_SELECT(对应扫描源选择),取值1为顶部进纸器,但直接设置设备对象属性而非扫描项属性,或缺少配套属性设置,都会触发参数错误。
修正后的代码
Function ScanJpeg(strFile As String) As Boolean On Error GoTo ErrLabel Dim wiaDialog As New WIA.CommonDialog Dim wiaScanner As WIA.Device Dim wiaScanItem As WIA.Item Dim wiaImg As WIA.ImageFile Dim targetProp As WIA.Property ScanJpeg = False Set wiaScanner = wiaDialog.ShowSelectDevice Set wiaScanItem = wiaScanner.Items(1) ' 检查并设置扫描源为顶部进纸器 On Error Resume Next Set targetProp = wiaScanItem.Properties("3088") On Error GoTo ErrLabel If Not targetProp Is Nothing Then ' 1=顶部进纸器,2=玻璃板,0=无 targetProp.Value = 1 ' 配套设置:扫描进纸器中所有页面(3096为WIA_DPS_PAGES,0表示全部) wiaScanItem.Properties("3096").Value = 0 Else MsgBox "当前设备不支持顶部进纸器设置" GoTo ExitLabel End If Set wiaImg = wiaScanItem.Transfer(wiaFormatJPEG) wiaImg.SaveFile strFile ScanJpeg = True ExitLabel: On Error Resume Next Set wiaImg = Nothing Set wiaScanItem = Nothing Set wiaScanner = Nothing Set wiaDialog = Nothing Exit Function ErrLabel: ErrHandler Err.Number, Err.Description Resume ExitLabel End Function
关键修正点
- 调整属性设置目标:扫描源属性属于
Item对象(扫描任务项),而非Device对象(设备本身),修正后避免参数不匹配 - 添加属性存在性检查:防止因设备不支持该属性直接赋值导致报错
- 补充配套属性:设置
3096属性确保扫描进纸器内所有纸张,符合进纸器的扫描逻辑
额外排查建议
- 确认佳能Color Network ScanGear 2驱动为最新版本,旧驱动可能存在WIA属性兼容问题
- 手动打开扫描软件测试顶部进纸器,排除硬件或驱动本身的故障
- 若仍报错,可使用WIA属性查看工具(如WIA Property Viewer)查看设备实际支持的属性及合法取值,确保
3088属性的取值符合设备要求
内容的提问来源于stack exchange,提问作者TheMortiestMorty
相关产品推荐
相关产品推荐

