Access 2000
I have a check scanner from Magtek, (MicrImage) This is like a "point
of sale" check scanner/credit card reader. Magtek furnished 2 ocx's
(MTMicrImage.oc x & SaxComm8.ocx). They also give example VB code.
I need to make this work in Access. I know the following code will
require a lot of modification for VBA.
My Problem is getting started - I have copied the ocx's to the
system32 folder and registered them. I also have a reference to them
in Access.
How do I create the "Object" so I can use the methods of the ocx?
Here is the VB code Example -
*************** *************** *************** *************** **
Private Sub LogStatus(ByVal InfoToLog As String)
txtStatus.Text = txtStatus.Text & InfoToLog & vbCrLf
txtStatus.SelLe ngth = 0
txtStatus.SelSt art = Len(txtStatus.T ext)
End Sub
Private Sub cmdClear_Click( )
txtStatus.Text = ""
txtMagStripeDat a.Text = ""
txtFirstName.Te xt = ""
txtLastName.Tex t = ""
txtMonth.Text = ""
txtYear.Text = ""
txtTrack1.Text = ""
txtTrack2.Text = ""
txtTrack3.Text = ""
txtAccountNum.T ext = ""
txtMicrData.Tex t = ""
txtMicrAccountN um.Text = ""
txtCheckNum.Tex t = ""
txtTransit.Text = ""
txtFileName.Tex t = ""
txtIFD.Text = ""
txtTagNum.Text = ""
txtTagOutput.Te xt = ""
cmdGetTagByNum. Enabled = False
cmdGetAllTags.E nabled = False
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdGetAllTags_C lick()
Dim ReturnVal As Variant
Dim FieldCount As Integer
Dim i As Integer
Dim TagNum As Long
LogStatus "Getting All Tags in file " & txtFileName.Tex t & ": "
ReturnVal = MicrImage.EnumT iffTags(txtFile Name.Text, txtIFD.Text)
If IsArray(ReturnV al) Then
FieldCount = UBound(ReturnVa l)
LogStatus "There are " & FieldCount & " Tags"
For i = 1 To FieldCount
TagNum = MicrImage.GetTi ffTagNumByIndex (txtFileName.Te xt, i,
txtIFD.Text)
LogStatus " Tag # " & TagNum & "= " &
MicrImage.GetTi ffTagByNumber(t xtFileName.Text , TagNum, txtIFD.Text)
Next
Else
LogStatus "There are No Tags in IFD " & txtIFD.Text & " in file " &
txtFileName.Tex t
End If
End Sub
Private Sub cmdGetTagByNum_ Click()
LogStatus "Getting Tag By Tag Number:"
txtTagOutput.Te xt = MicrImage.GetTi ffTagByNumber(t xtFileName.Text ,
txtTagNum.Text, txtIFD.Text)
End Sub
Private Sub cmdPortOpen_Cli ck()
If Not (MicrImage.Port Open) Then
MicrImage.CommP ort = txtCommPort.Tex t
MicrImage.Setti ngs = txtSettings.Tex t
End If
MicrImage.PortO pen = Not MicrImage.PortO pen
If MicrImage.PortO pen Then
LogStatus "Port Opened"
cmdPortOpen.Cap tion = "Close Port"
If MicrImage.DSRHo lding Then
LogStatus "Device Attached"
'Displays Current Switch Settings
'If you use the MicrImage.Save command then these do not need to be
sent
'every time you open the device
MicrImage.MicrT imeOut = 1
LogStatus "These are the Current Switch Settings"
LogStatus " Switch A: " & MicrImage.MicrC ommand("SWA", True)
LogStatus " Switch B: " & MicrImage.MicrC ommand("SWB", True)
LogStatus " Switch C: " & MicrImage.MicrC ommand("SWC", True)
LogStatus " Switch D: " & MicrImage.MicrC ommand("SWD", True)
LogStatus " Switch E: " & MicrImage.MicrC ommand("SWE", True)
LogStatus " Switch I: " & MicrImage.MicrC ommand("SWI", True)
LogStatus " Switch HW: " & MicrImage.MicrC ommand("HW", True)
'Sets Switch Settings
'If you use the MicrImage.Save command then these do not need to be
sent
'every time you open the device
MicrImage.MicrC ommand "SWA 00100010", False
MicrImage.MicrC ommand "SWB 00100010", False
MicrImage.MicrC ommand "SWC 00100000", False
MicrImage.MicrC ommand "HW 00111100", False
MicrImage.MicrC ommand "SWE 00000010", False
MicrImage.MicrC ommand "SWI 00000000", False
'MicrImage.Save
'Displays New Settings
'If you use the MicrImage.Save command then these do not need to be
sent
'every time you open the device
LogStatus "These are the New Switch Settings:"
LogStatus " Switch A: " & MicrImage.MicrC ommand("SWA", True)
LogStatus " Switch B: " & MicrImage.MicrC ommand("SWB", True)
LogStatus " Switch C: " & MicrImage.MicrC ommand("SWC", True)
LogStatus " Switch D: " & MicrImage.MicrC ommand("SWD", True)
LogStatus " Switch E: " & MicrImage.MicrC ommand("SWE", True)
LogStatus " Switch I: " & MicrImage.MicrC ommand("SWI", True)
LogStatus " Switch HW: " & MicrImage.MicrC ommand("HW", True)
'The OCX will work with any Micr Format. You just need to know which
'format is being used to parse it using the FindElement Method
LogStatus "Changing Format to 6200 for this Demo"
MicrImage.Forma tChange "6200"
LogStatus "Version: " & MicrImage.Versi on
MicrImage.MicrT imeOut = 2
Else
LogStatus "Device Not Attached"
End If
Else
LogStatus "Port Closed"
cmdPortOpen.Cap tion = "Open Port"
End If
End Sub
Private Sub Form_Load()
txtCommPort.Tex t = MicrImage.GetDe fSetting("CommP ort", "1")
txtSettings.Tex t = MicrImage.GetDe fSetting("Setti ngs", "115200,N,8 ,1")
lblCaption(0).C aption = App.ProductName
lblCaption(1).C aption = App.ProductName
End Sub
Private Sub MicrImage1_Micr DataReceived()
Dim ImagePath As String
Dim ImageFileName As String
Dim ImageIndex As String
Dim Status As Long
Dim StatusMsg As String
Dim bOpStatus As Boolean
If MicrImage.GetTr ack(1) & MicrImage.GetTr ack(2) &
MicrImage.GetTr ack(3) <"" Then
LogStatus "Event Fired: MagStripe Data"
txtMagStripeDat a.Text = MicrImage.MicrD ata
txtFirstName.Te xt = MicrImage.GetFN ame()
txtLastName.Tex t = MicrImage.GetLN ame()
txtMonth.Text = MicrImage.FindE lement(2, "=", 2, "2", False)
txtYear.Text = MicrImage.FindE lement(2, "=", 0, "2", False)
txtTrack1.Text = MicrImage.GetTr ack(1)
txtTrack2.Text = MicrImage.GetTr ack(2)
txtTrack3.Text = MicrImage.GetTr ack(3)
txtAccountNum.T ext = MicrImage.FindE lement(2, ";", 0, "=", False)
Else
LogStatus "Event Fired: Micr Data"
txtMicrData.Tex t = MicrImage.MicrD ata
txtMicrAccountN um.Text = MicrImage.FindE lement(0, "TT", 0, "A", False)
txtCheckNum.Tex t = MicrImage.FindE lement(0, "A", 0, "12", False)
txtTransit.Text = MicrImage.FindE lement(0, "T", 0, "TT", False)
ImagePath = MicrImage.GetDe fSetting("Image Path", "C:\")
'This sets up and index number so that we can deal with same check
being
'inserted over and over. The TransmitCurrent Image Method with fail if
the file
'already exists. This is to ensure that no check image is overwritten.
By keeping
'an ImageIndex and incrementing it we ensure that the same file name
will not be
'generated below. You are free to name the file anything that is
considered to be
'a valid file name.
ImageIndex = MicrImage.GetDe fSetting("Image Index", "0")
ImageIndex = CStr(CInt(Image Index) + 1)
MicrImage.SaveD efSetting "ImageIndex ", ImageIndex
ImageFileName = ImagePath & "MI" & txtTransit.Text &
txtMicrAccountN um.Text & txtCheckNum.Tex t & ImageIndex & ".TIF"
LogStatus "Acquiring File: " & ImageFileName & " ..."
'Adding a tiff tag.
MicrImage.AddTa g ("T32768=Thi s was added by the Demo Program")
'Transmitting current image
Status = MicrImage.Trans mitCurrentImage (ImageFileName, StatusMsg)
'Logging status of TransmitCurrent Image
LogStatus "TransmitCurren tImage: " & Status
If Status = "0" Then
bOpStatus = ShellEx(ImageFi leName, , , , , Me.hWnd)
If bOpStatus = True Then
LogStatus "Shell Successful"
'setting up the Image Info
txtFileName.Tex t = ImageFileName
txtIFD.Text = "1"
txtTagNum.Text = "270"
cmdGetTagByNum. Enabled = True
cmdGetAllTags.E nabled = True
Else
LogStatus "Shell Failed"
cmdGetTagByNum. Enabled = False
cmdGetAllTags.E nabled = False
End If
End If
End If
MicrImage.Clear Buffer
End Sub
Private Sub mnuAbout_Click( )
frmAbout.Show vbModal
End Sub
Private Sub mnuExit_Click()
Unload Me
End Sub
*************** *************** *************** *********
Thanks
Dale
I have a check scanner from Magtek, (MicrImage) This is like a "point
of sale" check scanner/credit card reader. Magtek furnished 2 ocx's
(MTMicrImage.oc x & SaxComm8.ocx). They also give example VB code.
I need to make this work in Access. I know the following code will
require a lot of modification for VBA.
My Problem is getting started - I have copied the ocx's to the
system32 folder and registered them. I also have a reference to them
in Access.
How do I create the "Object" so I can use the methods of the ocx?
Here is the VB code Example -
*************** *************** *************** *************** **
Private Sub LogStatus(ByVal InfoToLog As String)
txtStatus.Text = txtStatus.Text & InfoToLog & vbCrLf
txtStatus.SelLe ngth = 0
txtStatus.SelSt art = Len(txtStatus.T ext)
End Sub
Private Sub cmdClear_Click( )
txtStatus.Text = ""
txtMagStripeDat a.Text = ""
txtFirstName.Te xt = ""
txtLastName.Tex t = ""
txtMonth.Text = ""
txtYear.Text = ""
txtTrack1.Text = ""
txtTrack2.Text = ""
txtTrack3.Text = ""
txtAccountNum.T ext = ""
txtMicrData.Tex t = ""
txtMicrAccountN um.Text = ""
txtCheckNum.Tex t = ""
txtTransit.Text = ""
txtFileName.Tex t = ""
txtIFD.Text = ""
txtTagNum.Text = ""
txtTagOutput.Te xt = ""
cmdGetTagByNum. Enabled = False
cmdGetAllTags.E nabled = False
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdGetAllTags_C lick()
Dim ReturnVal As Variant
Dim FieldCount As Integer
Dim i As Integer
Dim TagNum As Long
LogStatus "Getting All Tags in file " & txtFileName.Tex t & ": "
ReturnVal = MicrImage.EnumT iffTags(txtFile Name.Text, txtIFD.Text)
If IsArray(ReturnV al) Then
FieldCount = UBound(ReturnVa l)
LogStatus "There are " & FieldCount & " Tags"
For i = 1 To FieldCount
TagNum = MicrImage.GetTi ffTagNumByIndex (txtFileName.Te xt, i,
txtIFD.Text)
LogStatus " Tag # " & TagNum & "= " &
MicrImage.GetTi ffTagByNumber(t xtFileName.Text , TagNum, txtIFD.Text)
Next
Else
LogStatus "There are No Tags in IFD " & txtIFD.Text & " in file " &
txtFileName.Tex t
End If
End Sub
Private Sub cmdGetTagByNum_ Click()
LogStatus "Getting Tag By Tag Number:"
txtTagOutput.Te xt = MicrImage.GetTi ffTagByNumber(t xtFileName.Text ,
txtTagNum.Text, txtIFD.Text)
End Sub
Private Sub cmdPortOpen_Cli ck()
If Not (MicrImage.Port Open) Then
MicrImage.CommP ort = txtCommPort.Tex t
MicrImage.Setti ngs = txtSettings.Tex t
End If
MicrImage.PortO pen = Not MicrImage.PortO pen
If MicrImage.PortO pen Then
LogStatus "Port Opened"
cmdPortOpen.Cap tion = "Close Port"
If MicrImage.DSRHo lding Then
LogStatus "Device Attached"
'Displays Current Switch Settings
'If you use the MicrImage.Save command then these do not need to be
sent
'every time you open the device
MicrImage.MicrT imeOut = 1
LogStatus "These are the Current Switch Settings"
LogStatus " Switch A: " & MicrImage.MicrC ommand("SWA", True)
LogStatus " Switch B: " & MicrImage.MicrC ommand("SWB", True)
LogStatus " Switch C: " & MicrImage.MicrC ommand("SWC", True)
LogStatus " Switch D: " & MicrImage.MicrC ommand("SWD", True)
LogStatus " Switch E: " & MicrImage.MicrC ommand("SWE", True)
LogStatus " Switch I: " & MicrImage.MicrC ommand("SWI", True)
LogStatus " Switch HW: " & MicrImage.MicrC ommand("HW", True)
'Sets Switch Settings
'If you use the MicrImage.Save command then these do not need to be
sent
'every time you open the device
MicrImage.MicrC ommand "SWA 00100010", False
MicrImage.MicrC ommand "SWB 00100010", False
MicrImage.MicrC ommand "SWC 00100000", False
MicrImage.MicrC ommand "HW 00111100", False
MicrImage.MicrC ommand "SWE 00000010", False
MicrImage.MicrC ommand "SWI 00000000", False
'MicrImage.Save
'Displays New Settings
'If you use the MicrImage.Save command then these do not need to be
sent
'every time you open the device
LogStatus "These are the New Switch Settings:"
LogStatus " Switch A: " & MicrImage.MicrC ommand("SWA", True)
LogStatus " Switch B: " & MicrImage.MicrC ommand("SWB", True)
LogStatus " Switch C: " & MicrImage.MicrC ommand("SWC", True)
LogStatus " Switch D: " & MicrImage.MicrC ommand("SWD", True)
LogStatus " Switch E: " & MicrImage.MicrC ommand("SWE", True)
LogStatus " Switch I: " & MicrImage.MicrC ommand("SWI", True)
LogStatus " Switch HW: " & MicrImage.MicrC ommand("HW", True)
'The OCX will work with any Micr Format. You just need to know which
'format is being used to parse it using the FindElement Method
LogStatus "Changing Format to 6200 for this Demo"
MicrImage.Forma tChange "6200"
LogStatus "Version: " & MicrImage.Versi on
MicrImage.MicrT imeOut = 2
Else
LogStatus "Device Not Attached"
End If
Else
LogStatus "Port Closed"
cmdPortOpen.Cap tion = "Open Port"
End If
End Sub
Private Sub Form_Load()
txtCommPort.Tex t = MicrImage.GetDe fSetting("CommP ort", "1")
txtSettings.Tex t = MicrImage.GetDe fSetting("Setti ngs", "115200,N,8 ,1")
lblCaption(0).C aption = App.ProductName
lblCaption(1).C aption = App.ProductName
End Sub
Private Sub MicrImage1_Micr DataReceived()
Dim ImagePath As String
Dim ImageFileName As String
Dim ImageIndex As String
Dim Status As Long
Dim StatusMsg As String
Dim bOpStatus As Boolean
If MicrImage.GetTr ack(1) & MicrImage.GetTr ack(2) &
MicrImage.GetTr ack(3) <"" Then
LogStatus "Event Fired: MagStripe Data"
txtMagStripeDat a.Text = MicrImage.MicrD ata
txtFirstName.Te xt = MicrImage.GetFN ame()
txtLastName.Tex t = MicrImage.GetLN ame()
txtMonth.Text = MicrImage.FindE lement(2, "=", 2, "2", False)
txtYear.Text = MicrImage.FindE lement(2, "=", 0, "2", False)
txtTrack1.Text = MicrImage.GetTr ack(1)
txtTrack2.Text = MicrImage.GetTr ack(2)
txtTrack3.Text = MicrImage.GetTr ack(3)
txtAccountNum.T ext = MicrImage.FindE lement(2, ";", 0, "=", False)
Else
LogStatus "Event Fired: Micr Data"
txtMicrData.Tex t = MicrImage.MicrD ata
txtMicrAccountN um.Text = MicrImage.FindE lement(0, "TT", 0, "A", False)
txtCheckNum.Tex t = MicrImage.FindE lement(0, "A", 0, "12", False)
txtTransit.Text = MicrImage.FindE lement(0, "T", 0, "TT", False)
ImagePath = MicrImage.GetDe fSetting("Image Path", "C:\")
'This sets up and index number so that we can deal with same check
being
'inserted over and over. The TransmitCurrent Image Method with fail if
the file
'already exists. This is to ensure that no check image is overwritten.
By keeping
'an ImageIndex and incrementing it we ensure that the same file name
will not be
'generated below. You are free to name the file anything that is
considered to be
'a valid file name.
ImageIndex = MicrImage.GetDe fSetting("Image Index", "0")
ImageIndex = CStr(CInt(Image Index) + 1)
MicrImage.SaveD efSetting "ImageIndex ", ImageIndex
ImageFileName = ImagePath & "MI" & txtTransit.Text &
txtMicrAccountN um.Text & txtCheckNum.Tex t & ImageIndex & ".TIF"
LogStatus "Acquiring File: " & ImageFileName & " ..."
'Adding a tiff tag.
MicrImage.AddTa g ("T32768=Thi s was added by the Demo Program")
'Transmitting current image
Status = MicrImage.Trans mitCurrentImage (ImageFileName, StatusMsg)
'Logging status of TransmitCurrent Image
LogStatus "TransmitCurren tImage: " & Status
If Status = "0" Then
bOpStatus = ShellEx(ImageFi leName, , , , , Me.hWnd)
If bOpStatus = True Then
LogStatus "Shell Successful"
'setting up the Image Info
txtFileName.Tex t = ImageFileName
txtIFD.Text = "1"
txtTagNum.Text = "270"
cmdGetTagByNum. Enabled = True
cmdGetAllTags.E nabled = True
Else
LogStatus "Shell Failed"
cmdGetTagByNum. Enabled = False
cmdGetAllTags.E nabled = False
End If
End If
End If
MicrImage.Clear Buffer
End Sub
Private Sub mnuAbout_Click( )
frmAbout.Show vbModal
End Sub
Private Sub mnuExit_Click()
Unload Me
End Sub
*************** *************** *************** *********
Thanks
Dale