Private Sub btnScan_Click()
Dim FileLocation As String
Dim Dpath As String
Dim x As String
Dim fso As Object
Dim scanDiag As Object
Dim Image As Object


' ایجاد شیء FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")

' تعیین مسیر ذخیره تصویر
Dpath = CurrentProject.Path & "\pic"
x = "Y" & Left(Forms!sanad1!tarikh_sand, 4) & "S" & Forms!sanad1!radif_sand & "F" & Forms!info!radif_factor & ".jpg"

FileLocation = Dpath & "" & x

' بررسی وجود فایل و حذف آن در صورت وجود
If fso.FileExists(FileLocation) Then
fso.DeleteFile FileLocation
End If

' ایجاد شیء CommonDialog برای اسکن تصویر
Set scanDiag = CreateObject("WIA.CommonDialog")

' اسکن تصویر
On Error GoTo ErrorHandler
Set Image = scanDiag.ShowAcquireImage()

' ذخیره تصویر اسکن شده
Image.SaveFile FileLocation

' نمایش تصویر در کنترل تصویر
masire_asli = FileLocation
imgFactor.Picture = FileLocation

Exit Sub


ErrorHandler:
MsgBox "خطا در اسکن تصویر: " & Err.Description, vbExclamation, "خطا"
End Sub کتاب خانه WIA را راهم دانلود کنید و به کتاب خانه اضافه کن