objects and loops PLEASE HELP!!!

  • Thread starter Thread starter Krzysztof via AccessMonster.com
  • Start date Start date
K

Krzysztof via AccessMonster.com

Good Day!

I am trying to set up a generic and very simple object operation to see if i
could acheive something in this fashion. i am trying to set up a 'dynamic
variable' and i am having no luck. this is what i have so far:


Dim x As Integer
Dim obj As TextBox
Dim roller As String

Do Until x = 6
x = 1
roller = "Text" + Str(x)
obj.Name = roller

obj.Text = "Test" //this will be replaced by several modules

x = x + 1
Loop

i need to know if this logic flow is acceptable, and i keep getting this
message:

"Object Variable or with block variable not set"

has anyone ever done this?

TIA

~K
 
First, you have to set a reference to an object before you can address it.
Because the object type you want to address is textbox, then you need to tell
Access what the text boxes belong to. So:

Dim frm As Form
Dim ctls As Controls
Dim ctl As Control
Dim intX as Integer
Dim strFormName As String

strFormName = "SomeForm"

'First see if the form is loaded
'Open it if it is not
If Application.CurrentProject.AllForms(strFormName).IsLoaded Then
If Application.CurrentProject.AllForms(strFormName).CurrentView <>
acViewDesign Then
MsgBox "The Form Must be open ind Design View to change control
Names"
Exit Sub
End If
Else
DoCmd.OpenForm strFormName, acDesign, , , , acHidden
End If

Set frm = Forms(strFormName)
Set ctls = Me.Controls

For Each ctl In ctls
If ctl.ControlType = acTextBox Then
ctl.Name = "Text" & intX
intX = intX + 1
End If
Next

Set frm = Nothing
Set ctls = Nothing
Set ctl = Nothing
For Each ctl In
Do Until x = 6
x = 1
roller = "Text" + Str(x)
obj.Name = roller

obj.Text = "Test" //this will be replaced by several modules

x = x + 1
Loop
 
In addition to Klatuu's advice, note that you're resetting the value of x
inside the loop, which would result in an infinite loop.
 

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

Back
Top