need help with an image problem

MIkeD666

Registered User.
Local time
Today, 04:42
Joined
Jan 12, 2019
Messages
59
I have bit of code below, that should open a image file. Namely a jpg file, that i or the user selected for the dialog box.
But i keep getting an error "error message 20=Microsoft can't open the file'C:\Users\miked\2\LandM\images\6jpg'
i have put in the references libraries as you can see in the image attached.

the aim of the code is to show the user which file at the file address he is attaching to the record

Am beging to think i have miss of forgot some thing

Sorry about the spelling but am dyslexic with Parksons.

this is the code



Private Sub fileNamePicked(i)


'open file dialog box to open a file
On Error GoTo SubError


'Add " Microsoft office 14.0 object library " in referances and
'visual basic for app
'M/c Access 16.0 object libary
'OLE AUTO
' M/C office 16.0 database eng
'mc office 16.0 object labary
'm/c script runtime


Dim FDialog As Office.FileDialog
Dim Varfile As Variant ' the varfile is the name fo files shown in the fdialog box

txtSelectedName = ""
' set up the file Dialog
Set FDialog = Application.FileDialog(msoFileDialogFilePicker)

With FDialog
.Title = " Pick the photo file you want to import but you can only pick gif or jpg files types"
.AllowMultiSelect = True ' note for images set this to false
.InitialFileName = "C:\Users\miked\OneDrive\2\LandM\images\" 'Folder picker needs trailing slash, this will leave the filr name at the botton blank

.Filters.Clear
.Filters.Add "gif image files", "*.Gif*"
.Filters.Add "JPG image files", "*.jpg*"
.Filters.Add "png image files", "*.PNG*"
'below are extra file filtters you maay wish to use
'.Filters.Add " Excel files", "*.xls*"
'.Filters.Add " Excel files", "*.xlsx*"
'.Filters.Add " Excel files, macro enabled", "*.xlsm*"

If .show = True Then ' the user picked open, if is false userpick cancal
If .SelectedItems.Count = 0 Then
MsgBox "You did not pick a file", , , vbCritical + vbOKOnly, _
"an error has occrred"
GoTo SubExit
End If

'the for loop below is used only whenmulit select is true
For Each Varfile In .SelectedItems
txtSelectedName = txtSelectedName & Varfile & vbCrLf '(vbcrlf is for a carrage return to start a new line)
Next
Else
'user cancelled dialog without choosing

End If
End With
Dim s As String
s = txtSelectedName

If i = 1 Then
Me.Imagebox1.PictureType = 0
Me.imageAdd1 = s
Me.Imagebox1.Picture = s
Me.Imagebox1.Requery


'Me.Imagebox1.Picture = s
' Me.Imagebox1.Visible = True
'Me.Imagebox1.Requery

End If
If i = 2 Then
Me.Imagebox2.PictureType = 0
Me.imageAdd2 = txtSelectedName
Me.Imagebox2 = txtSelectedName
Me.Imagebox2.Requery
End If


GoTo SubExit

SubExit:
On Error Resume Next
Set FDialog = Nothing
Exit Sub

SubError:
MsgBox " an Error number:" & Err.Number & " = " & Err.Description, vbCritical + vbOKOnly, _
"AN error occurrred"



End Sub
 

Attachments

  • access refer windo.png
    access refer windo.png
    60.9 KB · Views: 589
if multiselect is set to True, you need to use a Listbox (not textbox)
change this:

'the for loop below is used only whenmulit select is true
For Each Varfile In .SelectedItems
txtSelectedName = txtSelectedName & Varfile & vbCrLf '(vbcrlf is for a carrage return to start a new line)
Next

To:

'the for loop below is used only whenmulit select is true
Dim i As Integer
For i = 0 To [ListboxName].ListCount-1
[ListboxName].RemoveItem 0
Next
For Each Varfile In .SelectedItems
[ListboxName].AddItem Varfile
Next
 
thank you so much, now you point it out, it obverse
 

Users who are viewing this thread

Back
Top Bottom