Create and save embedded bitmap image

O

ondine

I'm trying to add a control on to a form to take a person's
signature. I'm not using a tablet pc, just a usb tablet and pen. I
would like to load the form with a blank bitmap or jpeg image in the
control, get the signature and then save the image on close as an
external file - if that's really not possible then we could save it as
an OLE object or image field in the record. Ideally I would just name
the file with the unique Id of the record so that it can be fetched
back when needed.

I've tried adding an unbound OLE paint control, but can't seem to save
the image - I used the code:
SavePicture Me!imgSig.Object, stFile
and got the error:
The component doesn't support Automation.

Also, the idea is to edit the image directly in the form, rather than
by opening Paint, which I managed by setting the verb to 1.

I had a look at using MS Ink but that seems to be formulated for
Tablet pc's.

Has anyone had any experience with this? I'm a bit lost!

Any suggestions would be great, thanks.
 
J

Jon Lewis

This may or may not help you but here's how I store and update user
signatures in Access. The signature will have been pre-created in a bitmap
editor.

The form (bound to a users table) has 4 Command Buttons cmdApply, cmdClose,
cmdDelete & cmdBrowse (which uses the Windows API GetOpenFileName to return
the path of the bitmap signature that is selected) plus textBox txtUserPath.
The browsed to signature is displayed in an Image control imgSignature and
cmdApply saves the image path to a field UserPath (the control source of a
textbox txtUserPath) and the image itself as an OLE Object to the field
UserSignature to which a Bound Object Frame bofSignature is bound.

Option Compare Database
Option Explicit

Private Sub cmdBrowse_Click()
On Error GoTo Err_cmdBrowse_Click
Dim filebox As OPENFILENAME
Dim Result As Long
Dim strPath As String
With filebox
.lStructSize = Len(filebox)
.hwndOwner = Me.hwnd
.hInstance = 0
.lpstrFilter = "Bitmap Files (*.bmp)" & vbNullChar & "*.bmp" &
vbNullChar & vbNullChar
.nMaxCustomFilter = 0
.nFilterIndex = 1
.lpstrFile = ""
.lpstrFile = Space$(254)
.nMaxFile = 255
.lpstrFileTitle = Space$(254)
.nMaxFileTitle = 255
.lpstrInitialDir = CurrentDBDir & vbNullChar
.lpstrTitle = "Select Signature" & vbNullChar
.flags = OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY Or OFN_PATHMUSTEXIST
Or OFN_EXPLORER Or OFN_LONGNAMES
.nFileOffset = 0
.nFileExtension = 0
.lCustData = 0
.lpfnHook = 0
End With
Result = GetOpenFileName(filebox)
If Result <> 0 Then
strPath = Left(filebox.lpstrFile, InStr(filebox.lpstrFile, vbNullChar) -
1)
Me.imgSignature.Picture = strPath
Me.cmdApply.Enabled = True
End If
Exit_cmdBrowse_Click:
Exit Sub
Err_cmdBrowse_Click:
MsgBox Err.Description, vbExclamation, "Customer Manager"
Resume Exit_cmdBrowse_Click
End Sub

Private Sub cmdApply_Click()
On Error GoTo Err_cmdApply_Click
If MsgBox("Are you sure you want to store the selected signature and
overwrite any existing stored signature?", vbOKCancel + vbQuestion,
"Customer Manager") = vbOK Then
With Me.bofSignature
..Enabled = True
..Locked = False
..SourceDoc = Me.imgSignature.Picture
..Action = acOLECreateLink
DoCmd.RunCommand acCmdSaveRecord
Me.txtUserPath = .SourceDoc
cmdClose.SetFocus
..Locked = True
..Enabled = False
End With
cmdDelete.Enabled = True
cmdApply.Enabled = False
End If
Exit_cmdApply_Click:
Exit Sub
Err_cmdApply_Click:
MsgBox Err.Description, vbExclamation, "Customer Manager"
Resume Exit_cmdApply_Click
End Sub

Private Sub cmdClose_Click()
DoCmd.Close acForm, "frmSignature"
End Sub

Private Sub cmdDelete_Click()
If MsgBox("Are you sure you want to delete the stored signature?",
vbOKCancel + vbQuestion, "Customer Manager") = vbOK Then
Me.UserSignature = Null
Me.txtUserPath = Null
With Me.bofSignature
..Enabled = True
..Locked = False
..Requery
..Locked = True
..Enabled = False
End With
If Not Me.imgSignature.Picture = "(None)" Then
cmdApply.Enabled = True
cmdApply.SetFocus
Else
cmdBrowse.SetFocus
End If
Me.cmdDelete.Enabled = False
End If
End Sub

Private Sub Form_Current()
Me.Caption = Me.Caption & " " & Me.txtUserName
If IsNull(Me.UserSignature) Then
Me.cmdDelete.Enabled = False
End If
End Sub

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top