Picture and Common Dialog problems

Pete64

Registered User.
Local time
Today, 09:26
Joined
Jul 1, 2003
Messages
37
Basically am new to Access so am lookin for help

Heres my problem, I'm tryin to create a form with a button which opens up a common dialog box and when I select a graphic file with the dialog it will update my database with a new path to the file I open and possible display the new image on the form. I've tried this without success this is what I've tried:

1. I have an Table "ImageTable" with one field "ImagePath"
2. I have a form "ImageForm" which consists of two buttons
"Add new graphic" and "Delete" which will delete the current record or graphic
3. Onclick of "Add new graphic" this dialog works
Me!Text13 = LaunchCD(Me)
4. Updates PictureFrame to common dialog entry

after this I have no clue what to do

I get the following error: Run time error '3163' the field is to small to accept the amount of data you attempted to add. Try inserting or pasting less data.

-I tested this and thought the common dialog path was creating unessary spaces so trimmed the path and its still not workin

Any help would be nice.com
----------
Regards
Pete
----------
 
Pete:

Post the common dialog code...

I bet that you have the following:

OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1

it should be...

OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(255, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1

Since a text field can only hold 255 characters then you cannot have the length of your text field be 257 characters.

HTH
 
Pete64 said:
1. I have an Table "ImageTable" with one field "ImagePath"

...

I get the following error: Run time error '3163' the field is to small to accept the amount of data you attempted to add. Try inserting or pasting less data.

Is your field ImagePath a text field? If so, what did you set field size to? (Default is 50, might not be enough. Might have to set it to 255.)

Hope this helps!

Could you post your code? I'd like to see how yo uare doing it as I've been wanting to do the same thing.
 
Last edited:
Cos...



OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(255, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1

Needs to be changed...

Here is a sample db on how to link and display pictures...

(Originally developed by Candice Tripp)
 

Attachments

Long Post

Hi Pete

I had a similar problem with a database that I created last year. It was a database that is used to store digital photographs. I'll post what I did and hopefully you'll be able to change bits to meet your needs.

The form searched for *.jpg; *.bmp; *.gif; *.pcd; *.png; *.php; *.pza; *.ufx; *.tif files.

I had a search form - FrmDirectories
On the form was a list box, which stored all of the image files within the directory chosen by the user - lstFiles
A textbox that stored the path - TxtPath
An Image box that displayed a picture of the image - Image1
Three cmd buttons
CmdBrowse - Opened the Common Dialog Box
CmdGetFiles - This searched for all of the image files within the directory specified from the Common Dialog Box.
CmdAdd - This opened another form (FrmAddPhoto) and added the image to the database.
I also had a table that was used to store the files that found in the specified directory - TblDirectories. This was made up of an Autonumber field and a Filepath text field (length 75 characters)

Now for the code.

Behind the search form (FrmDirectories) I had the following code

Option Compare Database

Private Sub CmdAdd_Click()
DoCmd.OpenForm "frmAddPhoto", acNormal, , , acFormAdd, acWindowNormal, Me!lstFiles
End Sub

Private Sub cmdBrowse_Click()
Dim lpIDList As Long
Dim sBuffer As String
Dim szTitle As String
Dim tBrowseInfo As BROWSEINFO
szTitle = "Search in:-"
With tBrowseInfo
.hWndOwner = Me.hwnd
.lpszTitle = lstrcat(szTitle, "")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
End With
lpIDList = SHBrowseForFolder(tBrowseInfo)
If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
txtPath = sBuffer
txtPath.SetFocus
cmdGetFiles.Enabled = True
End If
End Sub

Private Sub cmdGetFiles_Click()

Dim X As Integer

Dim strSQL As String
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM tblDirectories"
DoCmd.SetWarnings True
lstFiles.Requery
X = FindAllFiles(txtPath)
lstFiles.Requery

End Sub

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

Dim strSQL As String
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM tblDirectories"
DoCmd.SetWarnings True
lstFiles.Requery
CmdAdd.Enabled = False
cmdGetFiles.Enabled = False


Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open

End Sub

Private Sub lstFiles_Click()
Me!Image1.Picture = Me!lstFiles
CmdAdd.Enabled = True
cmdGetFiles.Enabled = False
End Sub

I then had 2 modules. The first basBrowse had the following code

Option Compare Database

Public Const BIF_RETURNONLYFSDIRS = 1
Public Const BIF_DONTGOBELOWDOMAIN = 2
Public Const MAX_PATH = 260
Declare Function SHBrowseForFolder Lib _
"shell32" (lpBI As BROWSEINFO) As Long
Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList _
As Long, ByVal lpBuffer As String) As Long
Declare Function lstrcat Lib "kernel32" _
Alias "lstrcatA" (ByVal lpString1 As String, ByVal _
lpString2 As String) As Long
Public Type BROWSEINFO
hWndOwner As Long
pidlRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

The second module basSearchFiles had the code

Option Compare Database
Option Explicit

Function FindAllFiles(Path As String)
On Error GoTo err_FindAllFiles

Dim intCounter As Integer
Dim strFiles As String
Dim strFileName As String
intCounter = 0

With Application.FileSearch
.LookIn = Path
.SearchSubFolders = True
.filename = "*.jpg; *.bmp; *.gif; *.pcd; *.png; *.php; *.pza; *.ufx; *.tif"
.Execute

If .Execute() > 0 Then
Dim db As Database
Dim rstFilesFound As Recordset
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found.", vbOKOnly, "PhotoView"
Set db = CurrentDb()

Set rstFilesFound = db.OpenRecordset("tblDirectories")

For intCounter = 1 To .FoundFiles.Count
strFileName = .FoundFiles(intCounter)
rstFilesFound.AddNew
rstFilesFound("FilePath") = strFileName
rstFilesFound.Update
Next intCounter
Else
MsgBox "There were no files found."

End If
End With

rstFilesFound.Close
db.Close
Set rstFilesFound = Nothing
Set db = Nothing

exit_FindAllFiles:
Exit Function

err_FindAllFiles:
MsgBox Err.Description
Resume exit_FindAllFiles

End Function

Sorry for the long post
HTH

Dave
 

Users who are viewing this thread

Back
Top Bottom