About coloring the textbox and save it to my database (1 Viewer)

mhacky01

Registered User.
Local time
Yesterday, 16:54
Joined
Oct 21, 2013
Messages
12
Good day guys! can somebody help me how can i do this?

here's the scenario

table1:
Name text
age numbers
sex text
date date
box1 text

now when i create form i want the "box1" change color when i triggered 1st click it turns blue then 2nd click it turns red then 3rd click white the it repeat the cycle.

and after i choose a color i want to save it. along with my records

how can i do this?


here's my form
//i648.photobucket.com/albums/uu202/TOKX_photo/colors_zps8854cdea.jpg
 

pr2-eugin

Super Moderator
Local time
Today, 00:54
Joined
Nov 30, 2011
Messages
8,494
On the Form Open initiate a variable with a value 1, then on Click of the rectangle increment the value, along with a Select Case that will change the color of the box. Something along the lines of
Code:
Option Compare Database
Option Explicit

Dim colorVal As Long

Private Sub Form_Open(Cancel As Integer)
    colorVal = 1
End Sub

Private Sub yourRectangleName_Click()
    Select Case colorVal Mod 3
        Case 1
            Me.yourRectangleName.BackColor = vbBlue
        Case 2
            Me.yourRectangleName.BackColor = vbRed
        Case 0
            Me.yourRectangleName.BackColor = vbWhite
    End Select
    colorVal = colorVal + 1
End Sub

Private Sub saveButton_Click()
    Me.yourColorField = Me.yourRectangleName.BackColor
End Sub
 

mhacky01

Registered User.
Local time
Yesterday, 16:54
Joined
Oct 21, 2013
Messages
12
Thanks for the response i successfully change the color of the textbox now what i want is to save it permanent on each record...

can you please examine my ms access?

im new in to ms access programming can you pls show me how to do it?
 

Attachments

  • Color.accdb
    1.1 MB · Views: 75

pr2-eugin

Super Moderator
Local time
Today, 00:54
Joined
Nov 30, 2011
Messages
8,494
If you have looked at my code carefully, I have the last Sub that does that for you..
Code:
Private Sub saveButton_Click()
    Me.yourColorField = Me.yourRectangleName.BackColor
End Sub

PS: I have not looked at the DB file..
 

mhacky01

Registered User.
Local time
Yesterday, 16:54
Joined
Oct 21, 2013
Messages
12
sir when i save it and add new record the text box appear the color code not the "color physically" if u check my accdb and try to save a color on the textbox only color code "number" saved not the color it self on the text box

and what is "your colorfield?"

sorry for being a noob

thanks so much sir...
 

pr2-eugin

Super Moderator
Local time
Today, 00:54
Joined
Nov 30, 2011
Messages
8,494
Colors are denoted by Number.. Variants would be Hex values (as in HTML) or RGB which still are Numbers at the end of the day.. IF you want you might be needing to write some code in the save button click; to store the color name based on their Number value.. 255 is Red, 0 is Black (on top of my head)..
 

mhacky01

Registered User.
Local time
Yesterday, 16:54
Joined
Oct 21, 2013
Messages
12
actually sir that's my main problem i dont know how to do it..
can you please show me the code how to do it?

when i save a record it save along with my colored textbox not just the color code in textbox...

so when i search or browse every record i know what color the person is.. because it shows on the textbox or rectangle object.

can you pls show me?? please sir? im really appreciate it
 

pr2-eugin

Super Moderator
Local time
Today, 00:54
Joined
Nov 30, 2011
Messages
8,494
Okay either I am confused or you are not describing the problem correctly.. Give another shot at explaining what you want.. Exactly..

There is no need for the Values to be Strings.. That is just going to be a overhead in coding..
 

mhacky01

Registered User.
Local time
Yesterday, 16:54
Joined
Oct 21, 2013
Messages
12
Ok sir here's what i wanto to achieve..

The scenario is i want to give every record on my database a color per person

For example when i fill it up:

Name: jason
Age: 22
Date: 9/2/13
Sex: male
Color1: RED (actual color it self not numbers or text will appear on this field)
Color2: Blue (actual color it self not numbers or text will appear on this field)
Color3: White (actual color it self not numbers or text will appear on this field)

Then save it..

Which is the "color field" will appear on this Databse is color and not the color numbers. So when i search every name in my database i know what color there are
 

pr2-eugin

Super Moderator
Local time
Today, 00:54
Joined
Nov 30, 2011
Messages
8,494
Check the attachment.. What I have done is created a new table, which will have all the Color names with their appropriate Color values.. If you check the Query Qry_getMeColorName, you will see the color name..

Also, I made the text box UNBOUND.
 

Attachments

  • EDITED_Color.accdb
    460 KB · Views: 73

mhacky01

Registered User.
Local time
Yesterday, 16:54
Joined
Oct 21, 2013
Messages
12
Wow!!!! it works like a charm!!!
now i have to create more colored textbox...


thank you so much!! for your time sir!!

CHEERS!!!! \m/!!!
 

ADG

New member
Local time
Today, 05:24
Joined
Mar 8, 2020
Messages
1
Dear sir pr2_eugin I couldn't open the attachment Edited_Color.accdb . any clue please...
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 19:54
Joined
May 21, 2018
Messages
8,554
FYI, that was posted 7 years ago so might not have luck with PR2 getting back to you.
I can download without problem and open it. May have gotten corrupted in download. I would try downloading again.
 

Users who are viewing this thread

Top Bottom