Hello
I don't know a thing about writing VBA Codes but this forum I was able thas helped me to finally figure out how to link the pictures to a path etc on a form. Everything works fine on the form - the pictures change with each employee etc, etc. However, when I select the command button "change picture" or "Remove", it opens the dialog box or the folder on the c:\drive etc and I can select a new picture or the one for deletion; BUT I also get a message which says compile error, syntax error and it highlights in yellow the name Private Sub cmdInsertPic_Click(). The name of the form in which the employee data is stored is Employee Profile Form (from the table Employee Profile). The computer highlights the word "Profile" and gives the error (Expected =). It is possible that it is the spacing between the three words in the file name is the problem because if I were to rename the form to a single word, it works. The section with the error is emboldened. The code is listed below. Any assistance you can provide would be appreciated.
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([ImagePath]) Then .lpstrFile = [ImagePath]
.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
[ImagePath] = OFN.lpstrFile
Forms!Employee Profile Form![ImageFrame].Picture = [ImagePath]
SysCmd acSysCmdSetStatus, "Afbeelding: '" & [ImagePath] & "'."
End If
Exit Sub
Err_cmdInsertPic_Click:
MsgBox Err.Description, vbExclamation
End Sub
Thank you
Forsi
I don't know a thing about writing VBA Codes but this forum I was able thas helped me to finally figure out how to link the pictures to a path etc on a form. Everything works fine on the form - the pictures change with each employee etc, etc. However, when I select the command button "change picture" or "Remove", it opens the dialog box or the folder on the c:\drive etc and I can select a new picture or the one for deletion; BUT I also get a message which says compile error, syntax error and it highlights in yellow the name Private Sub cmdInsertPic_Click(). The name of the form in which the employee data is stored is Employee Profile Form (from the table Employee Profile). The computer highlights the word "Profile" and gives the error (Expected =). It is possible that it is the spacing between the three words in the file name is the problem because if I were to rename the form to a single word, it works. The section with the error is emboldened. The code is listed below. Any assistance you can provide would be appreciated.
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([ImagePath]) Then .lpstrFile = [ImagePath]
.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
[ImagePath] = OFN.lpstrFile
Forms!Employee Profile Form![ImageFrame].Picture = [ImagePath]
SysCmd acSysCmdSetStatus, "Afbeelding: '" & [ImagePath] & "'."
End If
Exit Sub
Err_cmdInsertPic_Click:
MsgBox Err.Description, vbExclamation
End Sub
Thank you
Forsi
Last edited: