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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting new value in text box

Status
Not open for further replies.

awhitsel

Programmer
Feb 22, 2001
80
0
0
US
I want to be able to change a value in a text box, but I am getting a run-time error 2448 (You can't assign a value to this object.) Here is the code that I am currently using (the current value of the text box is a carat (^), and I want to change it to a letter A):

Select Case PER1ID_11Value
Case "A" To "Z"
PER1ID_11Value = [Forms]![frmCorrect]![txtPER1ID_11]
Case "a" To "z"
PER1ID_11Value = [Forms]![frmCorrect]![txtPER1ID_11]
Case "0" To "9"
PER1ID_11Value = [Forms]![frmCorrect]![txtPER1ID_11]
Case Else
PER1ID_11Value = "A"
[Forms]![frmCorrect]![txtPER1ID_11] = PER1ID_11Value
End Select

Please advise.

Thanks.
 
You simply want to change and carat (^) into A???

Why not try:

If Chr(Me![fieldname]) = 94 Then Me![Fieldname] = "A"

Otherwise, I would recommend not checking for all the values you want to keep. Instead, figure out what you don't want, check for that and change as necessary. I have some code that will determine if a field has only alhpanumeric characters (A-Z, a-z, 0-9). It returns a true/false depending. Then I have some other code that goes through the field on character at a time and changes all the "bad" characters...I can help with that if you need it.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
The carat was randomly placed in the text box as a result of an encryption module that was run earlier in the program. The conditions are that the resulting encrypted character must either be a letter or a number - no oddball characters.

I am writing a correction module to handle this problem.

That is the reason that I need to force the change to the text box.
 
No problem....

Do you just need to replace any carats (or any other character for that matter) with another character (such as the A)???? You could use my replace character code in an update query or wherever you need it and just have them changed that way.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Yes, any oddball characters that appear need to replaced with either a letter or a number.

I tried doing an update query on my end for replacing the characters, but it went nowhere.

Please advise.

Thanks.
 
The below code will do what you want.....what you do is the following. Copy this code and paste it into a global module. In the update query, use:

dhTranslate([fieldname], "^", "A")

in the updateto field. Something to remember, this is a one to one replace, unless the two sides don't match. For example, if you use:

dhTranslate([fieldname], "!@#$%^&*()<>?:;'[]{}", "A")

all those characters will become As. If you use:

dhTranslate([fieldname], "!@#$%^&*()", "ABCDEFG")

then all !s become As, @s become Bs, and so on....any left over at the end (such as &*() in this example) will become Gs, becuase this is the closest one to one match.

Code:
Public Function dhTranslate(ByVal strIn As String, ByVal strMapIn As String, _
    ByVal strMapOut As String) As String

    Dim lngI As Long
    Dim lngPos As Long
    Dim strChar As String * 1
    Dim strOut As String
    
    'If there's no list of characters to replace, there's no point going on with the work
    If Len(strMapIn) > 0 Then
        'Right fill the strMapOut set
        If Len(strMapOut) > 0 Then
            strMapOut = Left$(strMapOut & String(Len(strMapIn), Right$(strMapOut, 1)), Len(strMapIn))
        End If
        For lngI = 1 To Len(strIn)
            strChar = Mid$(strIn, lngI, 1)
            lngPos = InStr(1, strMapIn, strChar, vbBinaryCompare)
            If lngPos > 0 Then
                'If strMapOut is empty, this doesn't fail, because Mid handles empty strings gracefully
                strOut = strOut & Mid$(strMapOut, lngPos, 1)
            Else
                strOut = strOut & strChar
            End If
        Next lngI
    End If
    dhTranslate = strOut

End Function

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top