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!

Indirection, substitution?

Status
Not open for further replies.

Darrylles

Programmer
Feb 7, 2002
1,758
0
0
GB
Hi,

Forgotten the term for what I want to do, I think it's known as indirection (although it may be substitution).

Eg:
==================================
dim x as string

x=(value in a textbox)

forms!myform.x = "a string"
==================================

X is assigned a value in a textbox. The value will be one of many other textbox names.

I then want to be able to refer to the textbox control via the 'x' variable.

Hope that's clear enough.

Regards,

Darrylle









"Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
You could do something like...


Private Sub Command2_Click()
Dim intIndx As Integer
Dim ctlTextBox As TextBox

'Loop through all form controls

For intIndx = 0 To Me.Controls.Count - 1
'if control is a text box then
If (TypeOf Me.Controls(intIndx) Is TextBox) Then
'if textbox's name matches value of txtName on form
If Me.Controls(intIndx).Name = Me!txtName.Value Then
'set ctlTextBox to this textbox
Set ctlTextBox = Me.Controls(intIndx)
End If
End If
Next
'you can then use ctlTextbox as you would use
'any normal textbox
'eg.

ctlTextBox.Value = "Hello"

End Sub
 
Hi Darrylle,

How are you doing. Long time no hear. I think the following might answer your question:

x = Forms!Form1!YourTextBox
Forms!frmYourForm(x) = "a string"

Providing x gets a text value which represents a "writeable" text control, this should work.

Cheers,
Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
Hoping I understood clearly what you needed:

Use VB notation:
Set ctr = Forms("FormName")(x)
MsgBox "Control " & ctr.Name & " has the value " & ctr[.Value]


not Access notation:
set ctr = Forms![FormName]!x -this doesn't work

...
HTH

Dan

[pipe]
 
My response a little inconsistent. Should have been:

x = Forms!frmYourForm!YourTextBox
Forms!frmYourForm(x) = "a string"
Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
Hiya,

Thanks all - I managed to get the required result after messing with GHoldens response. Thnx GH.

It pretty well turned out like Steve01 and danvlas examples.

Still seems a bit messy.

Hi Steve - yep - I've kept out of here for a while, 'fraid I get too involved in semantics.

I aim to help, but take it all too seriously.

Regards and thnx again all,

Darrylle



"Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
Hello,

I am having some trouble with indirection. I read the thread from Aug 7 02 which referred to a control on a form, I am trying to apply it to populating a table from another table. I am in Access 97.

Source Table Plan has these fields:
Contract - Text 10 eg 1231231234
CC - Text 8 eg 8110
Name - Text 40 Fred
WEF - Date 04/21/03
StatusCode - Text 1 P
PlanHours - Single 40

Target Table StaffPlan has these fields:

ContractNum - Text 10
CC - Text 8
EmpName - Text 40
StatusCode - Text 1
TotalPlan - Single
then a field for every week in field WEF from table "Plan" in yymmdd format eg '030407' '030414' '030421' etc - each of which is Single to hold the hours from the plan table.

Here is my code segment:

Dim MyWeeksHours As Field
Set rst = dbs.OpenRecordset("Plan", DB_OPEN_DYNASET)
Set rstTarget = dbs.OpenRecordset("StaffPlan", DB_OPEN_DYNASET)

With rst
.MoveFirst
Do Until .EOF
rstTarget.MoveFirst
Do Until rstTarget.EOF
If ![CONTRACT] = rstTarget![ContractNum] And ![CC] = rstTarget![CC] And ![Name] = rstTarget![EmpName] Then
rstTarget.Edit
MyWeeksHours = Format(![WEF], "yymmdd")
rstTarget!MyWeeksHours = ![PlanHours]
rstTarget.Update
End If
rstTarget.MoveNext
Loop
rstTarget.close
.MoveNext
Loop
.close
End With

Set dbs = Nothing

It falls over on the
MyWeeksHours = Format(![WEF], "yymmdd")
part saying "Object variable or With block variable not set"

I am sure that I am overlooking something really simple...
MyWeeksHours should hold the field name that I am trying to set.

Many thanks

Bryan
 
Bryan,

Your code looks OK to me. I'm not immediately able to reproduce the error with it; as you say, its probably something simple.

I do produce a similar error if I put a .Close statement immediately before the "fall over" line, but this situation would'nt appear to be the case in your code (ie. the recordset won't close whilst you're in the loop).

Suggest you single step the code, to see where about in the data the problem is occuring; ie. first record, last record etc. Use a small test file.

Good luck,




Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top