The problem with a continuous form view is that there is really only one
copy of unbound controls on the form at a time, so what you do to the one in
the current record/row will happen to all of them. There is an exception,
using Conditional Formatting will allow for each row to be different (Access
2000 and newer).
The Load event code you are using will run on the current record, the first
one in the subform at the time of the load unless you have more code above
this that moves to another record. What you could do though is use
Conditional Formatting on the ID textbox. In form design view, right click
the ID textbox and choose Conditional Formatting. Set the Default Formatting
to be one of the fore colors, then for Condition 1 choose Expression Is in
the combo box. For the expression, use a "user defined function" to
determine if the picture exists. You will need to pass this function the
value of the ID textbox and have the function return True or False. Set the
fore color to the other color.
Example expression:
FileExists([txtID]) = True
Example function (using your FileExists code):
Public Function FileExists(lngID As Long) As Boolean
On Error Resume Next
Dim temp As String, Path As String
Select Case lngID
Case Is <10000
path = CurrentProject.path & "\oapic0_9K\" & lngID & ".jpg"
Case 10000 To 20000
path = CurrentProject.path & "\oapic10_19K\" & lngID & ".jpg"
Case Else
End Select
temp = Dir(Path, vbHidden Or vbSystem Or vbArchive Or vbReadOnly)
FileExists = ((Len(temp) > 0) And (Err.number = 0))
End Function
I assumed the ID number to be a number (Long), if it is text, change the
function to show lngID to be a String. Also, VB will probably make the
conversion for you, but if there is a problem in concatenating the path and
lngID is a number, wrap it in CStr(lngID).
--
Wayne Morgan
MS Access MVP
"worldbadger" <wo*********@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hello there,
I have a subform that has anywhere from 20-500 ID numbers (unique)
listed on it. Each ID is going to be linked to a picture. First off I
set up a check for existance of the file;
Public Function fileexists(Name As String) As Boolean
On Error Resume Next
Dim temp As String
temp = Dir(Name, vbHidden Or vbSystem Or vbArchive Or vbReadOnly)
fileexists = ((Len(temp) > 0) And (Err.number = 0))
End Function
Now what I want to do is have the form look at the textbox (ID) and
then determine if the ID has a picture. If it does change the text
color of the ID text box to red other wise leave it black. Here is
what I have and it is not working correctly.
Private Sub Form_Load()
Dim path As String
If Me.sfmblue.Form.Controls("ID") < 10000 Then
path = CurrentProject.path & "\oapic0_9K\" &
Me.sfmblue.Form.Controls("ID") & ".jpg"
ElseIf Me.sfmblue.Form.Controls("ID") > 9999 And
Me.sfmblue.Form.Controls("ID") < 20000 Then
path = CurrentProject.path & "\oapic10_19K\" &
Me.sfmblue.Form.Controls("ID") & ".jpg"
End If
If fileexists(path) = True Then
Me.sfmblue.Form.Controls("ID").ForeColor = 255
Else
Me.sfmblue.Form.Controls("ID").ForeColor = -2147483640
End If
End Sub
Any help would be greatly appreciated.
worldbadger