Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refer to a textbox's name to change it's properties for a function.

Status
Not open for further replies.

r0nniem

Technical User
Dec 22, 2005
28
AU
Hi there,

I have 41 textboxes for a calendar. When I click on a text box I need it to change it's visual properties to indicate its been selected and if clicked again to be unselected. Not wanting to do this 41 times ... what do I call the "Current Text Box"?

If CurTextBox.BackColor = -2147483633 Then
CurTextBox.BackColor = 8421504
CurTextBox.SpecialEffect = 2
Else
Me![txtDate1] = Null
CurTextBox.SpecialEffect = 1
CurTextBox.BackColor = -2147483633
End If

Many thanks
Ronnie
 
You are still going to have to write and maintain 41 event procedures. If interested in only writing one event procedure:
Faq702-6904
 
MajP,
Why would 41 event procedures need to be written? You can create a simple function in the form's module like:
Code:
Function WhereAmI() As String
    Dim CurTextBox As Control
    Dim PrevTextBox As Control
    Set PrevTextBox = Screen.PreviousControl

    Set CurTextBox = Me.ActiveControl
    'I have no idea what this accomplishes ;-)
    If CurTextBox.BackColor = -2147483633 Then
        CurTextBox.BackColor = 8421504
        CurTextBox.SpecialEffect = 2
     Else
        'Me![txtDate1] = Null
        CurTextBox.SpecialEffect = 1
        CurTextBox.BackColor = -2147483633
    End If

End Function
Then select all 41 text boxes and set the On Got Focus event property to:
[tt][blue] =WhereAmI()[/blue][/tt]

Duane
Hook'D on Access
MS Access MVP
 
Hey guys ... thanks for your assistance ... again. I'm sure each of you have helped me out sometime in the past and I've read many of your posts. I appreciate all the experience and knowledege you have! THANK YOU! I'm just a mere reporting gal and just trying to improve things (and challenging myself)!

To let you know more, I'm having an crack at a roster system for our Tech's using the calendar the method shown below (can't remember where I got it from). I've seen many calendar suggestions, but nothing quite right.

The goal is to select a tech it'll update the calendar to their display their current rostered shifts/leave.

To add new shifts, I'm wanting the user to click on a date the calendar and it will shown in as 'pressed' and it will save the dates to a temporary table. If they want to unselect that date, they click a 2nd time and it will go back to original format (to indicate unselected) and deleted from the temporary table. They then click Ok for the bunch of selected dates then apply the shift details.

Wish me luck!


____________________________________________________________
Private Sub Form_Open(Cancel As Integer)

Me![txtFirstDate] = Date 'current date
Call filldates 'call function that fills in calendar

End Sub
____________________________________________________________
Private Function filldates()

Dim curday As Date, CurBox As Integer
curday = DateSerial(year(Me![txtFirstDate]), month(Me![txtFirstDate]), 1) 'first day of month
curday = DateAdd("d", 1 - Weekday(curday), curday) 'back to sunday

For CurBox = 0 To 41 'need to loop thru 42 textboxes
Me("D" & CurBox) = Day(curday)
Me("D" & CurBox).Visible = False
If month(curday) = month(Me!txtFirstDate) Then Me("D" & CurBox).Visible = True
curday = curday + 1 'nextday
Debug.Print CurBox
Next CurBox

End Function
 
Why not simply select all the textboxes in Design View, then goto Format - Conditional Formatting , select "Field has focus" and color it whatever you want?

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Hi Missinglinq,

Thanks for the suggestion. I looked into the Conditional Formatting option and I saw that it allowed me to change the background color, but I'm also changing the special effect property from raised to sunken too. I'm not sure if you can change this under the conditional formatting section ... can you?

Thanks
Ronnie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top