|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm creating a simple application solely in Access.
The table consists of several fields such as Id, name, description etc. and image. The idea is that as each new record is displayed in the form, the picture associated with that record is displayed. But I'm not sure how to enter image data into a table, nor can I get it to display on the form. Anyone know? Thanks, Lilibeta |
|
#2
|
|||
|
|||
|
I found this way of inserting images useful, take a look at the codes and functions and if you want a sample of it I can send it at your e-mail. it can display the images in the reports too.
Option Compare Database Option Explicit ' Code to display standard "Open File" dialog. Type OPENFILENAME lStructSize As Long hwndOwner As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _ "GetOpenFileNameA" (OFN As OPENFILENAME) As Boolean Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _ "GetSaveFileNameA" (OFN As OPENFILENAME) As Boolean Private Const ALLFILES = "All files" Function MakeFilterString(ParamArray varFilt() As Variant) As String ' Create filter string. ' Returns "" if there are no arguments. ' Expects an even number of arguments (filter name, extension). ' Adds *.* if the number of arguments is odd. Dim strFilter As String Dim intRes As Integer Dim intNum As Integer intNum = UBound(varFilt) If (intNum <> -1) Then For intRes = 0 To intNum strFilter = strFilter & varFilt(intRes) & vbNullChar Next If intNum Mod 2 = 0 Then strFilter = strFilter & "*.*" & vbNullChar End If strFilter = strFilter & vbNullChar End If MakeFilterString = strFilter End Function Private Sub InitOFN(OFN As OPENFILENAME) With OFN ' Initialize fields user doesn't want to know about .hwndOwner = hWndAccessApp .hInstance = 0 .lpstrCustomFilter = vbNullString .nMaxCustFilter = 0 .lpfnHook = 0 .lpTemplateName = 0 .lCustData = 0 .nMaxFile = 511 .lpstrFileTitle = String(512, vbNullChar) .nMaxFileTitle = 511 .lStructSize = Len(OFN) ' Use default filter if not specified. If .lpstrFilter = "" Then .lpstrFilter = MakeFilterString(ALLFILES) End If ' Pad lpstrFile with null chars. .lpstrFile = .lpstrFile & String(512 - Len(.lpstrFile), vbNullChar) End With End Sub Function OpenDialog(OFN As OPENFILENAME) As Boolean Dim intRes As Integer InitOFN OFN intRes = GetOpenFileName(OFN) If intRes Then ' Remove trailing null chars from lpstrFile. With OFN .lpstrFile = Left$(.lpstrFile, InStr(.lpstrFile, vbNullChar) - 1) End With End If OpenDialog = intRes End Function '_____________________________ 'The following subs are used on the form. '_____________________________ 'This sub is added to a Close Button. 'Private Sub cmdClose_Click() ' On Error Resume Next ' DoCmd.Close acForm, Me.Name 'End Sub '_______________________________ 'This button removes the picture 'Picfile is the name in TABLE 'imgPicture is the name of the field on the form 'Private Sub cmdErasePic_Click() ' If Not IsNull([PicFile]) Then ' If MsgBox("The image will be removed from this record. Are you sure?", vbYesNo + vbQuestion) = vbYes Then ' [imgPicture].Picture = "" ' [PicFile] = Null ' SysCmd acSysCmdClearStatus ' End If ' End If 'End Sub '________________________________ 'This sub is used together with module to open the dialog box 'Private Sub cmdInsertPic_Click() ' Dim OFN As OPENFILENAME ' On Error GoTo Err_cmdInsertPic_Click ' ' Set options for dialog box. ' With OFN ' .lpstrTitle = "Images" ' If Not IsNull([PicFile]) Then .lpstrFile = [PicFile] ' .flags = &H1804 ' OFN_FileMustExist + OFN_PathMustExist + OFN_HideReadOnly ' .lpstrFilter = MakeFilterString("Image files (*.bmp;*.gif;*.jpg;*.wmf)", "*.bmp;*.gif;*.jpg;*.wmf", _ ' "All files (*.*)", "*.*") ' End With ' If OpenDialog(OFN) Then ' [PicFile] = OFN.lpstrFile ' [imgPicture].Picture = [PicFile] ' SysCmd acSysCmdSetStatus, "Afbeelding: '" & [PicFile] & "'." ' End If ' Exit Sub 'Err_cmdInsertPic_Click: ' MsgBox Err.Description, vbExclamation 'End Sub '___________________________________ 'This sub placed in the Form_Current section. 'Private Sub Form_Current() ' On Error GoTo HandleErr ' If Not IsNull([PicFile]) Then ' [imgPicture].Picture = [PicFile] ' SysCmd acSysCmdSetStatus, "Image: '" & [PicFile] & "'." ' Else ' [imgPicture].Picture = "" ' SysCmd acSysCmdClearStatus ' End If ' Exit Sub 'HandleErr: ' If Err = 2220 Then ' [imgPicture].Picture = "" ' SysCmd acSysCmdSetStatus, "Can't open image: '" & [PicFile] & "'" ' Else ' MsgBox Err.Description, vbExclamation ' End If 'End Sub |
|
#3
|
|||
|
|||
|
Wow! That's a little daunting!
I've never worked with the code in Access before. Right about now I'm thinking that this would be a lot easier if I just did the database in Access and used Visual Basic for the forms. But I'll give this a try. Thanks! |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft Access Help > images in tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|