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

RETRIEVING TEXTBOX VALUES 1

Status
Not open for further replies.

GClinic

Technical User
Feb 16, 2008
13
Hi,
I have a myriad of textboxes on my form, and from time to time, I need to retrieve some of their values in comma-separated format. The textboxes are named in the format of a letter and two digits, for easy identification, like A22 or B54 etc.
Before a textbox is updated, I want a display of values in the adjoining boxes displayed to assist a user in making his decision.
This is the code that I tried on their got-focus event:

'If TypeOf Screen.ActiveControl Is TextBox Then
If IsNull(Screen.ActiveControl) Then
Dim X As Integer, P As Integer, Y As Integer, Z As Integer, S As String, Tx As Control, ImpoList As String
S = Screen.ActiveControl.Name
X = Mid(S, 2, 1)
Y = Right(S, 1)
Z = Screen.ActiveControl.Tag
For Each Tx In Screen.ActiveForm
If TypeOf Tx Is TextBox Then
If Tx.Name = "A" & Y & P Then
For P = 1 To 10
DoCmd.GoToControl Tx.Name
If Not IsNull(Tx) Then
ImpoList = ImpoList & "," & Tx.Text
End If
Next
End If
End If
Next
MsgBox ImpoList
End If
'End If

However, at the end of the event, my list is empty, when I can see several textboxes are not null. The code seems to work up to the line before:

Impolist = Impolist & "," & Tx.Text

What am I doing wrong?
 
What about this ?
ImpoList = ImpoList & "," & Tx.Value

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks.
I just tried your suggestion but it did not seem to work; the list is still empty.
 
And what about replacing this:
For Each Tx In Screen.ActiveForm
with this ?
For Each Tx In Screen.ActiveForm.Controls

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thangs again, but it did not work.
 
No On Error instruction somewhere in your procedure ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Actually, I had not got round to that part as I was still testing the code.
 

Try stepping through the code and checking values in the immediate window. I think you'll find that the last character in the value of tx.name is always a zero.


Randy
 
How are ya GClinic . . .

. . . and this:
Code:
[blue]   Dim frm As Form, idx As Integer, fldName As String, Pack As String
   
   Set frm = Forms![purple][b][i]FormName[/i][/b][/purple]
   
   For idx = 1 To 10
      fldName = "A" & CStr(idx)
      
      If Trim(frm(fldName) & "") <> "" Then
         If Pack = "" Then
            Pack = frm(fldName)
         Else
            Pack = Pack & ", " & frm(fldName)
         End If
      End If
   Next
   
   Debug.Print Pack[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thanks, TheAceMan1.
I must confess I did not quite understand the code you sent in but I tried it all the same. I got an error message.
 
what is the value of "p" in this line of code

If Tx.Name = "A" & Y & P Then

should your p loop be before this line?

ck1999
 
You need to give us some information if you want help.
gclinic said:
Thangs again, but it did not work.
What result DID you get?
gclinic said:
I got an error message.
What error message?

Have you tried stepping through the code and checking your values in the immediate window?



Randy
 
Just to clarify what this code is doing

assume your activecontrol is textbox named "A22"

Go through each control on form and determine if a control is a textbox
if there is a textbox AND its name is "a2" then
goto txtboxes "A21" "A22" "A23" "A24" "A25" "A26" "A27" "A28" "A29" "A210" and as long as textboxes have values and the value to impolist.

then display impolist in a msgbox

Is this what you want?

I doubt it.

ck1999
 
Thanks Guys,
I got a tip to change the line: "For Each Tx In Screen.ActiveForm" to "For Each Tx In Screen.ActiveForm.Controls". This has solved the problem so far.
I appreciate your efforts.
 
. . . and in my code, replace [purple]FormName[/purple] with the actual form name. If there's any spaces in the names use brackets:
Code:
[blue]Set frm = Forms!ClientData
   or
Set frm = Forms![Client Data][/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top