Hi, I have a main form about vegetable species which include information about common name, scientific name, crop group, fruit and taxonomy. The target of the database is to visually identify each specie through several corresponding images, so that main form has a continuous subform (sec1) with two textboxes (both bounded to the corresponding table fields): the image denomination -imageDen- and the name of the image jpg file –fileName- (both no required fields, with validation by code). And the main form has also a simple subform (sec2) that displays the image that matchs with the selected record in the continuous subform. When inserting a new record (a new image), you must write in the textbox named imageDen the image denomination and then press Enter, which makes a browsing dialog window appears. By selecting the jpg file in that dialog window, the code inserts the file name in the textbox named fileName of the continuous subform, set the boolean photoAllOk (see after) to True and also inserts the image like an OLE Object in the simple subform and displays that image on it.
The validation is implemented by checking the value of the boolean photoAllOk in the Form_BeforeUpdate event. If its value is False, a Yes / No message window appears indicating which of the two fields is null and asking if you want to cancel the insertion or modification of the record; if the response is Yes the instruction Me.Undo enters, if the response is No the instruction DoCmd.CancelEvent enters. The boolean photoAllOk is set to False in the event imageDen_Change and in the event imageDen_KeyPress if the key pressed is different than Enter. That boolean is also changed in the sec1_Exit event of the main form:
Private Sub sec1_Exit(Cancel As Integer)
If IsNull(Me.sec1.Form.imageDen.Value) = False Then
If Me.Sec1.Form.imageDen.Value <> "" Then
If IsNull(Me.Sec1.Form.FileName.Value) = False Then
If Me.Sec1.Form.FileName.Value <> "" Then
photoAllOk = True
Else
photoAllOk = False
End If
Else
photoAllOk = False
End If
Else
photoAllOk = False
End If
Else
photoAllOk = False
End If
The process of adding an image in Access 2000, Access 2002 and Access 2007 is like described. But in Access 2003 the code fails: after selecting the jpg file in the browsing dialog window the Yes / No message window of the Form_BeforeUpdate event appears indicating that the value in the textbox fileName is Null.
I have left only the lines:
strFilter = ahtAddFilterItem(strFilter, ".jpg")
photoAllOk = True
strInputFileName = ahtCommonFileOpenSave(ahtOFN_FILEMUSTEXIST, _
CurrentProject.Path, strFilter, , ".jpg", "", "Imagen para '" & Me.link & "':", hwnd, True)
photoAllOk = True
but the boolean photoAllOk keeps being set to False and appearing the message window indicating that the value of the textbox fileName is Null.
I have also tried with
photoAllOk = True
Dim fileName As String
Dim result As Integer
With Application.FileDialog(3) ' 3 is a constant: msoFileDialogFilePicker
.Title = "Select Employee Picture"
.Filters.Add "All Files", "*.*"
.Filters.Add "JPEGs", "*.jpg"
.Filters.Add "Bitmaps", "*.bmp"
.FilterIndex = 3
.AllowMultiSelect = False
.InitialFileName = CurrentProject.path
result = .Show
If (result <> 0) Then 'result = 0 if nothing was selected
fileName = Trim(.SelectedItems.Item(1))
'filename contains the path you want.
End If
End With
photoAllOk = True
with the same result.
Can anybody say a way of going around that, or another code for opening a browsing dialog window that can suit for the 2003 version?
Thanks for any help given.
The validation is implemented by checking the value of the boolean photoAllOk in the Form_BeforeUpdate event. If its value is False, a Yes / No message window appears indicating which of the two fields is null and asking if you want to cancel the insertion or modification of the record; if the response is Yes the instruction Me.Undo enters, if the response is No the instruction DoCmd.CancelEvent enters. The boolean photoAllOk is set to False in the event imageDen_Change and in the event imageDen_KeyPress if the key pressed is different than Enter. That boolean is also changed in the sec1_Exit event of the main form:
Private Sub sec1_Exit(Cancel As Integer)
If IsNull(Me.sec1.Form.imageDen.Value) = False Then
If Me.Sec1.Form.imageDen.Value <> "" Then
If IsNull(Me.Sec1.Form.FileName.Value) = False Then
If Me.Sec1.Form.FileName.Value <> "" Then
photoAllOk = True
Else
photoAllOk = False
End If
Else
photoAllOk = False
End If
Else
photoAllOk = False
End If
Else
photoAllOk = False
End If
The process of adding an image in Access 2000, Access 2002 and Access 2007 is like described. But in Access 2003 the code fails: after selecting the jpg file in the browsing dialog window the Yes / No message window of the Form_BeforeUpdate event appears indicating that the value in the textbox fileName is Null.
I have left only the lines:
strFilter = ahtAddFilterItem(strFilter, ".jpg")
photoAllOk = True
strInputFileName = ahtCommonFileOpenSave(ahtOFN_FILEMUSTEXIST, _
CurrentProject.Path, strFilter, , ".jpg", "", "Imagen para '" & Me.link & "':", hwnd, True)
photoAllOk = True
but the boolean photoAllOk keeps being set to False and appearing the message window indicating that the value of the textbox fileName is Null.
I have also tried with
photoAllOk = True
Dim fileName As String
Dim result As Integer
With Application.FileDialog(3) ' 3 is a constant: msoFileDialogFilePicker
.Title = "Select Employee Picture"
.Filters.Add "All Files", "*.*"
.Filters.Add "JPEGs", "*.jpg"
.Filters.Add "Bitmaps", "*.bmp"
.FilterIndex = 3
.AllowMultiSelect = False
.InitialFileName = CurrentProject.path
result = .Show
If (result <> 0) Then 'result = 0 if nothing was selected
fileName = Trim(.SelectedItems.Item(1))
'filename contains the path you want.
End If
End With
photoAllOk = True
with the same result.
Can anybody say a way of going around that, or another code for opening a browsing dialog window that can suit for the 2003 version?
Thanks for any help given.