473,388 Members | 1,230 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Altering fore colour properties only in selected field

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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub TrackTitle_AfterUpdate()
  3.  
  4.     AlbumSave.Enabled = True
  5.  
  6.     Dim folder As String
  7.     Dim number As String
  8.     Dim prefix As String
  9.     Dim name As String
  10.     Dim ext As String
  11.     Dim autonumbered As String
  12.     Dim Filepath As String
  13.  
  14.     folder = URLSource
  15.     number = TrackNumber
  16.  
  17.     If number < 10 Then
  18.         prefix = "0"
  19.     Else
  20.         prefix = ""
  21.     End If
  22.  
  23.     name = TrackTitle
  24.     ext = ExtensionSource
  25.     autonumbered = Numbered
  26.  
  27.     If autonumbered = "Yes" Then
  28.         Filepath = folder + "\" + prefix + number + " " + name + "." + ext
  29.     Else
  30.         Filepath = folder + "\" + name + "." + ext
  31.     End If
  32.  
  33.     URL = Filepath
  34.  
  35.     Dim fso
  36.     Dim File As String
  37.  
  38.     Dim red As Long
  39.     Dim green As Long
  40.  
  41.     red = RGB(255, 0, 0)
  42.     green = RGB(0, 128, 0)
  43.  
  44.     File = Filepath
  45.     Set fso = CreateObject("Scripting.FileSystemObject")
  46.  
  47.     If Not fso.FileExists(File) Then
  48.         URL.ForeColor = red
  49.     Else
  50.         URL.ForeColor = green
  51.     End If
  52.  
  53.     If URL.ForeColor = green Then
  54.         Play.Enabled = True
  55.     Else
  56.         Play.Enabled = False
  57.     End If
  58.  
  59.     If URL.ForeColor = red Then
  60.         Browsefile.SetFocus
  61.     Else
  62.         Play.SetFocus
  63.     End If
  64.  
  65. End Sub
  66.  
  67.  
Jan 6 '08 #1
4 2340
Megalog
378 Expert 256MB
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.
Jan 6 '08 #2
missinglinq
3,532 Expert 2GB
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

Expand|Select|Wrap|Line Numbers
  1. If Not fso.FileExists(File) Then
  2.    Me.ValidPath = 0
  3.  Else
  4.    Me.ValidPath = -1
  5. End If
  6.  
  7. If Me.ValidPath = -1   Then
  8. Play.Enabled = True
  9. Else
  10. Play.Enabled = False
  11. End If
  12.  
  13. If Me.ValidPath = 0 Then
  14. Browsefile.SetFocus
  15. Else
  16. Play.SetFocus
  17. End If
  18.  
  19. End Sub
  20.  
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)>
Jan 6 '08 #3
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

Expand|Select|Wrap|Line Numbers
  1. If Not fso.FileExists(File) Then
  2.    Me.ValidPath = 0
  3.  Else
  4.    Me.ValidPath = -1
  5. End If
  6.  
  7. If Me.ValidPath = -1   Then
  8. Play.Enabled = True
  9. Else
  10. Play.Enabled = False
  11. End If
  12.  
  13. If Me.ValidPath = 0 Then
  14. Browsefile.SetFocus
  15. Else
  16. Play.SetFocus
  17. End If
  18.  
  19. End Sub
  20.  
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)>
Jan 7 '08 #4
missinglinq
3,532 Expert 2GB
Glad we could be of help!

Linq ;0)>
Jan 7 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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
3
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...
7
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...
11
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...
11
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...
9
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. ...
10
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...
3
Corster
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...
1
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...
0
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,...
0
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...
0
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
0
BarryA
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.