Hi, I have a form in MS Access 2003 where the user types a file extension into one text box (e.g. mp3), a folder path into another text box (e.g. D:\Backup) and a song name into a third text box (e.g. Shallow). After the song name text box has been updated a procedure is run which attempts to generate a file path for the given song name and then output it to a fourth text box. In the above examples the result outputted to the file path text box would be D:\Backup\Shallow.mp3.
A second procedure then runs an existence check on the file path, if it is valid the text in the file path text box turns green and if it isn't the text turns red. The file extension text box and the folder path text box are contained in the form header. The song name text box and file path text box are contained in the detail and make up a record.
The above two procedures work fine, however if i create 3 records with valid file paths and then a fourth with an invalid file path, all four record's file path text box text turns red. Is there an option in the form properties or vba code that results in only the current record's file path text box fore colour being edited instead of all the records on the form?
Thanks,
The code for the song name text box after update is listed below: -
-
Private Sub TrackTitle_AfterUpdate()
-
-
AlbumSave.Enabled = True
-
-
Dim folder As String
-
Dim number As String
-
Dim prefix As String
-
Dim name As String
-
Dim ext As String
-
Dim autonumbered As String
-
Dim Filepath As String
-
-
folder = URLSource
-
number = TrackNumber
-
-
If number < 10 Then
-
prefix = "0"
-
Else
-
prefix = ""
-
End If
-
-
name = TrackTitle
-
ext = ExtensionSource
-
autonumbered = Numbered
-
-
If autonumbered = "Yes" Then
-
Filepath = folder + "\" + prefix + number + " " + name + "." + ext
-
Else
-
Filepath = folder + "\" + name + "." + ext
-
End If
-
-
URL = Filepath
-
-
Dim fso
-
Dim File As String
-
-
Dim red As Long
-
Dim green As Long
-
-
red = RGB(255, 0, 0)
-
green = RGB(0, 128, 0)
-
-
File = Filepath
-
Set fso = CreateObject("Scripting.FileSystemObject")
-
-
If Not fso.FileExists(File) Then
-
URL.ForeColor = red
-
Else
-
URL.ForeColor = green
-
End If
-
-
If URL.ForeColor = green Then
-
Play.Enabled = True
-
Else
-
Play.Enabled = False
-
End If
-
-
If URL.ForeColor = red Then
-
Browsefile.SetFocus
-
Else
-
Play.SetFocus
-
End If
-
-
End Sub
-
-
4 2340
Is this a single form? If so, then the problem is that your code is only triggering after an update to the data, so when you cycle through records the same color is still being applied since there's no OnCurrent event.
Is this a continuous form? If so, I dont think you can independantly color the records based on individual criteria using VBA, since all the objects are basically multiple instances of the same objects.
Now, I'm not using 2003 anymore, so cant remember if this works there, but in 2007 you can use conditional formatting in a continuous form. If it works for you, you can enable/disable playing with your filecheck routine (instead of setting the color, and using the color to determine .enabled = true/false) and then apply a conditional format however you like.
From the behavior you describe you're not speaking of a Single View form, and so, as Megalog said, Conditional Formatting is the route you need to take.
What I would do is add a Yes/No field to the underlying table. If your form is based on a query, be sure to go into Design View for the query and add the new field to the query so it's available to the form.
Instead of trying to set your fore colors in code, based on the validity of the path/filename, you'll need to modify your code so that if the path is valid, you set the value of the checkbox (let’s call it ValidPath) to -1.
Note that you won't actually have to place the Yes/No field on the form to reference or set it.
Now replace your code Lines 46 thru 64 with this code - If Not fso.FileExists(File) Then
-
Me.ValidPath = 0
-
Else
-
Me.ValidPath = -1
-
End If
-
-
If Me.ValidPath = -1 Then
-
Play.Enabled = True
-
Else
-
Play.Enabled = False
-
End If
-
-
If Me.ValidPath = 0 Then
-
Browsefile.SetFocus
-
Else
-
Play.SetFocus
-
End If
-
-
End Sub
-
Now select the URL textbox
Goto Format - Conditional Format
Under Condition1 select Expression Is
In the blank box enter [ValidPath] = -1
Set the fore color to Green
Hit Add, then
Under Condition2 select Expression Is
In the blank box enter [ValidPath] = 0
Set the fore color to Red
I think I've included everything, but I've had some distractions here! Post back if you have any problems.
Welcome to TheScripts!
Linq ;0)>
Thank you very much Megalog and missinglinq, It now works fine. The only alteration I had to make to the solution you suggested was to add the Yes/No field to the form as the code wouldn't work without it being there. This was not a problem, I just made the field invisible and unenabled. Thanks again!
From the behavior you describe you're not speaking of a Single View form, and so, as Megalog said, Conditional Formatting is the route you need to take.
What I would do is add a Yes/No field to the underlying table. If your form is based on a query, be sure to go into Design View for the query and add the new field to the query so it's available to the form.
Instead of trying to set your fore colors in code, based on the validity of the path/filename, you'll need to modify your code so that if the path is valid, you set the value of the checkbox (let’s call it ValidPath) to -1.
Note that you won't actually have to place the Yes/No field on the form to reference or set it.
Now replace your code Lines 46 thru 64 with this code - If Not fso.FileExists(File) Then
-
Me.ValidPath = 0
-
Else
-
Me.ValidPath = -1
-
End If
-
-
If Me.ValidPath = -1 Then
-
Play.Enabled = True
-
Else
-
Play.Enabled = False
-
End If
-
-
If Me.ValidPath = 0 Then
-
Browsefile.SetFocus
-
Else
-
Play.SetFocus
-
End If
-
-
End Sub
-
Now select the URL textbox
Goto Format - Conditional Format
Under Condition1 select Expression Is
In the blank box enter [ValidPath] = -1
Set the fore color to Green
Hit Add, then
Under Condition2 select Expression Is
In the blank box enter [ValidPath] = 0
Set the fore color to Red
I think I've included everything, but I've had some distractions here! Post back if you have any problems.
Welcome to TheScripts!
Linq ;0)>
Glad we could be of help!
Linq ;0)> Sign in to post your reply or Sign up for a free account.
Similar topics
by: Lapchien |
last post by:
One of my users has asked that a form change it's colour if a particular
yes/no box is ticked - possibly made a bit more tricky because the form is
tabular..?
Thanks,
Lap
|
by: Tim Marshall |
last post by:
I would swear that when I developed in A97, I could change the back
colour of a form.
However, in Windows XP, on both A97 and A2003, there no longer is a
property showing in the format tab for...
|
by: Donald Grove |
last post by:
Is it possible to retrieve field properties from a table in access2000
using code?
I have tried:
"
dim dbs as dao.database
dim tbl as dao.tabledef
dim fld as dao.field
dim prop as...
|
by: Tim Marshall |
last post by:
I use Terry Kreft's & Stephen Lebans colour dialog procedures for users
to pick colours for various control properties in certain apps.
Is there a way to take the colour code that is displayed in...
|
by: feeman |
last post by:
I have a problem is it possible to highlight a field on a report in
access 97.
If a tick appear in follow up call box, I would like access to
highlight the field. is this possible, I have...
|
by: JimmyKoolPantz |
last post by:
IDE: Visual Studio 2005
Language: VB.NET
Fox Pro Driver Version: 9.0.0.3504
Problem: I currently have a problem altering a DBF file. I do not get
any syntax errors when running the program. ...
|
by: webgirl |
last post by:
Hi there,
I've been searching the net & the forums here over the last few days for help with my problem & am getting myself really confused.. hoping someone may be able to help me here.
I've...
|
by: Corster |
last post by:
I'm fairly new to Access, so please have patience...
I have an application that I've written to audit all of our computers, monitors etc. which also works-out the Intel processor details from the...
|
by: Dave |
last post by:
I have created a number of combo boxes in my database, I simply want to
change the colour of the background when the selects the combo box. At the
moment when the user uses there mouse and hovers...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |