Textbox data

F

Fysh

I am using Access 2k. I have a textbox that when the form
loads, it automatically has some information in the
textbox. The user can continue to edit the textbox. After
they are finished editing they can select other
information on the form which can update the textbox as
well. However, I am running in circles. How can I reset
the textbox back to it's original state if a checkbox is
selected or unselected? The following works fine if the
user selects it once, but if they select, unselect, then
reselect it updates the textbox twice. I know this is
crazy, but believe me I can see some users actually doing
this.

Private Sub Anomaly_Enter()
Me!Anomaly.SelStart = Me!Anomaly.SelLength
End Sub

Private Sub Critical_AfterUpdate()
If Me.Critical = True Then
Me.Anomaly = "© " & Me.Anomaly
Else
Me.Anomaly = Me.Anomaly
End If
End Sub

Thanks for any responses
 
F

Fysh

Ok I think I was able to remove the redudancy, but how can
I remove the first two spaces (© ) from the textbox? Here
is what I came up with so far. Thanks for any responses

Private Sub Critical_AfterUpdate()

Dim AnyString, MyStr
AnyString = Me.Anomaly ' Define string.
MyStr = Left(AnyString, 1)

If Me.Critical = True Then
If MyStr = "©" Then
Else
Me.Anomaly = "© " & Me.Anomaly
End If
Else
Me.Anomaly = Me.Anomaly
End If
End Sub
 
F

Fysh

Ok I think I have it. Any MVPs out there, please provide
feedback if you see a better way.

Private Sub Critical_AfterUpdate()

Dim AnyString, MyStr
AnyString = Me.Anomaly ' Define string.
MyStr = Left(AnyString, 1)

If Me.Critical = True Then
If MyStr = "©" Then
Else
Me.Anomaly = "© " & Me.Anomaly
End If
Else
If MyStr = "©" Then
Me.Anomaly = Mid(AnyString, 3)
Else
End If
Me.Anomaly = Me.Anomaly
End If
End Sub
 
M

Marshall Barton

Fysh said:
Ok I think I have it. Any MVPs out there, please provide
feedback if you see a better way.

Private Sub Critical_AfterUpdate()

Dim AnyString, MyStr
AnyString = Me.Anomaly ' Define string.
MyStr = Left(AnyString, 1)

If Me.Critical = True Then
If MyStr = "©" Then
Else
Me.Anomaly = "© " & Me.Anomaly
End If
Else
If MyStr = "©" Then
Me.Anomaly = Mid(AnyString, 3)
Else
End If
Me.Anomaly = Me.Anomaly
End If
End Sub


You really haven't explained enough of the entire situation
to determine if that is a general solution or if it will
only work for thins one test case. What if the user checks
three of four check boxes and then goes back and deselects
one or two of them??

As far as the above code goes, If the character after tha @
sign is always a space, then you can check for that specific
situation :

Private Sub Critical_AfterUpdate()
If Me.Critical = True Then
If Left(Me.Anomaly, 2) <> "© " Then
Me.Anomaly = "© " & Me.Anomaly
End If
Else
If Left(Me.Anomaly, 2) = "© " Then
Me.Anomaly = Mid(AnyString, 3)
End If
End If
End Sub

Personally, I think it is better to store the individual
pieces of the constructed text in separate fields and put it
together only when you need to display the combined results,
but that may not be applicable to what ever you're trying to
accomplish here.
 
F

Fysh

Thanks Marshall for the response. Right now they can edit
the textbox anytime and if they check the critical box
then it updates the text box. This is the only time the
box will be changed. Thanks again for the suggestion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top