C
carcher
Hello. I am searching for a solution to a search form problem. I am not very
familiar with VBA coding, so please bear with me. I have an Access db with 2
tables...structures and images. They are joined (one to many) by StationID
with each StationID having multiple images associated with it.
I have a form that allows searching the structures table via a WHERE clause
and a command button to filter data entered in fields on the HEADER section
of the form (borrowed code from Allen Browne's help site). The filtered data
is displayed in the DETAIL section of the form.
My goal is to have the images for each StationID displayed with the filtered
detail results. I don't know how to get the image control to point to each
record displayed, and would really appreciate some detailed guidance.
tblImage (all text fields):
ImageID PK
ImageName
StationNo
structures (all text fields except Comments...Memo):
StationNo PK
StructureID
RiverStream
ItemNumber
SizeofPipeConduit
DateConstructed
Walkway
Account
OperatorType
Comments
Tables joined on StationNo with Structures.StationNo being the one side of
the relationship and tblImage.StationNo being the many.
Search form based on Structures table uses unbound text boxes and the
following where clause to query structures info:
Private Sub cmdFilter_Click()
Dim Whereclause As String
If Not IsNull(txtStationNo) Then
Whereclause = "[StationNo] Like '*" & txtStationNo & "*'"
End If
If Not IsNull(txtRiverStream) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[RiverStream] Like '*" & txtRiverStream & "*'"
End If
If Not IsNull(txtItemNumber) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[ItemNumber] Like '*" & txtItemNumber & "*'"
End If
If Not IsNull(txtStructureID) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[StructureID] Like '*" & txtStructureID & "*'"
End If
If Not IsNull(txtPipeSize) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[SizeofPipeConduit] Like '*" & txtPipeSize & "*'"
End If
If Not IsNull(txtDateConstructed1) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[DateConstructed] >= '" & txtDateConstructed1 &
"'"
End If
If Not IsNull(txtDateConstructed2) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[DateConstructed] <= '" & txtDateConstructed2 &
"'"
End If
If Not IsNull(txtWalkway) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[Walkway] Like '*" & txtWalkway & "*'"
End If
If Not IsNull(txtAccount) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[Account] Like '*" & txtAccount & "*'"
End If
If Not IsNull(txtTypeofOperator) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[OperatorType] Like '*" & txtTypeofOperator &
"*'"
End If
If Not IsNull(txtComments) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[Comments] Like '*" & txtComments & "*'"
End If
Me.Filter = Whereclause
Me.FilterOn = True
End Sub
Private Sub cmdReset_Click()
Dim ctl As Control
For Each ctl In Me.Section(acHeader).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
ctl.Value = Null
End Select
Next
Me.FilterOn = False
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
Cancel = True
MsgBox "You cannot add new structures to the search form.", vbInformation,
"Permission denied."
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.Filter = "(False)"
Me.FilterOn = True
End Sub
I've added a subform to the search form. The subform is based on the
tblimage table and contains all field from the table. The only visible field
is the ImageName field...I've added an image control called ImageFrame to the
subform, and set the subform's property to continuous then dragged the
subform into my search form. When opening the search form, errors off on the
form_Current event saying it can't find the file. If I leave off the
subform's Form_Current event he subform correctly displays the imagename for
each image(s) for each filtered detail form record, yet the ImageFrame
displays the same image for each ImageName.
Code for subform tblImageTest:
Option Compare Database
Option Explicit
Public Function GetImagePath() As String
GetImagePath = GetDBPath & "images\"
End Function
Public Function GetDBPath() As String
GetDBPath = CurrentProject.Path & "\"
End Function
Private Sub Form_AfterUpdate()
Dim strNoImage As String
If Dir(GetImagePath & Me![ImageName]) <> "" Then
Me![ImageFrame].Picture = GetImagePath & Me![ImageName]
Else
strNoImage = "c:\windows\no image available.jpg"
Me.ImageFrame.Picture = strNoImage
End If
On Error Resume Next
Me![ImageFrame].Picture = GetImagePath & Me![ImageName]
End Sub
Private Sub Form_Current()
Dim strNoImage As String
If Dir(GetImagePath & Me![ImageName]) <> "" Then
Me![ImageFrame].Picture = GetImagePath & Me![ImageName]
Else
strNoImage = "c:\windows\no image available.jpg"
Me.ImageFrame.Picture = strNoImage
End If
On Error Resume Next
Me![ImageFrame].Picture = GetImagePath & Me![ImageName]
End Sub
I apologize if this is too much information, but I am in over my head.
Thank you.
familiar with VBA coding, so please bear with me. I have an Access db with 2
tables...structures and images. They are joined (one to many) by StationID
with each StationID having multiple images associated with it.
I have a form that allows searching the structures table via a WHERE clause
and a command button to filter data entered in fields on the HEADER section
of the form (borrowed code from Allen Browne's help site). The filtered data
is displayed in the DETAIL section of the form.
My goal is to have the images for each StationID displayed with the filtered
detail results. I don't know how to get the image control to point to each
record displayed, and would really appreciate some detailed guidance.
tblImage (all text fields):
ImageID PK
ImageName
StationNo
structures (all text fields except Comments...Memo):
StationNo PK
StructureID
RiverStream
ItemNumber
SizeofPipeConduit
DateConstructed
Walkway
Account
OperatorType
Comments
Tables joined on StationNo with Structures.StationNo being the one side of
the relationship and tblImage.StationNo being the many.
Search form based on Structures table uses unbound text boxes and the
following where clause to query structures info:
Private Sub cmdFilter_Click()
Dim Whereclause As String
If Not IsNull(txtStationNo) Then
Whereclause = "[StationNo] Like '*" & txtStationNo & "*'"
End If
If Not IsNull(txtRiverStream) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[RiverStream] Like '*" & txtRiverStream & "*'"
End If
If Not IsNull(txtItemNumber) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[ItemNumber] Like '*" & txtItemNumber & "*'"
End If
If Not IsNull(txtStructureID) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[StructureID] Like '*" & txtStructureID & "*'"
End If
If Not IsNull(txtPipeSize) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[SizeofPipeConduit] Like '*" & txtPipeSize & "*'"
End If
If Not IsNull(txtDateConstructed1) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[DateConstructed] >= '" & txtDateConstructed1 &
"'"
End If
If Not IsNull(txtDateConstructed2) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[DateConstructed] <= '" & txtDateConstructed2 &
"'"
End If
If Not IsNull(txtWalkway) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[Walkway] Like '*" & txtWalkway & "*'"
End If
If Not IsNull(txtAccount) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[Account] Like '*" & txtAccount & "*'"
End If
If Not IsNull(txtTypeofOperator) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[OperatorType] Like '*" & txtTypeofOperator &
"*'"
End If
If Not IsNull(txtComments) Then
If Whereclause <> "" Then Whereclause = Whereclause & " AND "
Whereclause = Whereclause & "[Comments] Like '*" & txtComments & "*'"
End If
Me.Filter = Whereclause
Me.FilterOn = True
End Sub
Private Sub cmdReset_Click()
Dim ctl As Control
For Each ctl In Me.Section(acHeader).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
ctl.Value = Null
End Select
Next
Me.FilterOn = False
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
Cancel = True
MsgBox "You cannot add new structures to the search form.", vbInformation,
"Permission denied."
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.Filter = "(False)"
Me.FilterOn = True
End Sub
I've added a subform to the search form. The subform is based on the
tblimage table and contains all field from the table. The only visible field
is the ImageName field...I've added an image control called ImageFrame to the
subform, and set the subform's property to continuous then dragged the
subform into my search form. When opening the search form, errors off on the
form_Current event saying it can't find the file. If I leave off the
subform's Form_Current event he subform correctly displays the imagename for
each image(s) for each filtered detail form record, yet the ImageFrame
displays the same image for each ImageName.
Code for subform tblImageTest:
Option Compare Database
Option Explicit
Public Function GetImagePath() As String
GetImagePath = GetDBPath & "images\"
End Function
Public Function GetDBPath() As String
GetDBPath = CurrentProject.Path & "\"
End Function
Private Sub Form_AfterUpdate()
Dim strNoImage As String
If Dir(GetImagePath & Me![ImageName]) <> "" Then
Me![ImageFrame].Picture = GetImagePath & Me![ImageName]
Else
strNoImage = "c:\windows\no image available.jpg"
Me.ImageFrame.Picture = strNoImage
End If
On Error Resume Next
Me![ImageFrame].Picture = GetImagePath & Me![ImageName]
End Sub
Private Sub Form_Current()
Dim strNoImage As String
If Dir(GetImagePath & Me![ImageName]) <> "" Then
Me![ImageFrame].Picture = GetImagePath & Me![ImageName]
Else
strNoImage = "c:\windows\no image available.jpg"
Me.ImageFrame.Picture = strNoImage
End If
On Error Resume Next
Me![ImageFrame].Picture = GetImagePath & Me![ImageName]
End Sub
I apologize if this is too much information, but I am in over my head.
Thank you.