Recordset help

  • Thread starter gmazza via AccessMonster.com
  • Start date
G

gmazza via AccessMonster.com

Hey there,
I have a control form in which I put a value in, lets say Hello

In my open form, I open a recordset and when the the recordset hits the field.
name of the value, I am trying to do something like this:
Me.Controls("Text" & intCount).ControlSource = fld.Value

The intCount is 1
The Textbox that I want Hello to be displayed is called Text1

I keep getting an error saying Object doesn't support this property.

Please help, thanks!
 
B

Banana

gmazza said:
Hey there,
I have a control form in which I put a value in, lets say Hello

In my open form, I open a recordset and when the the recordset hits the field.
name of the value, I am trying to do something like this:
Me.Controls("Text" & intCount).ControlSource = fld.Value

The intCount is 1
The Textbox that I want Hello to be displayed is called Text1

I keep getting an error saying Object doesn't support this property.

Please help, thanks!

I think something else is amiss.

First, try doing this:

Me.Controls("Text" & intCount) = intCount

This is to verify that the left hand works.

Other thing, you're setting ControlSource = fld.Value. You didn't
explain what is the fld and I'm not sure if it actually makes sense to
set ControlSource to a value of a field... Did you mean to set a field
to a controlsource? If so, it should be ControlSource = fld.Name

But more importantly.... why? There may be in fact a better solution
than dynamically assigning fields to controls at runtime. Indeed, you
could simply set Me.Recordeet = rst and all controls with the
controlsource set accordingly would then pick up the field with same
name as named in controlsource, making it a simple matter of binding a
recordset based on query with correct aliasing for all given columns ->
controls.
 
G

gmazza via AccessMonster.com

Everything works, and I do want the value of the field in my table, the value
being Hello.
I want Hello in my textbox on my form.
Here is my IF statement in the middle of my recordset on my On Open event:
If fld.Name = "CriteriaValue" Then
If IsNull(fld.Value) Then
Else
With Me.Controls("Text" & intCount)
.Caption = fld.Value
.Visible = True
.FontBold = True
End With

Else
intCount = intCount + 1
With Me.Controls("Text" & intCount)
Me.Controls("Text" & intCount).ControlSource = fld.Value
.FontBold = False
.Visible = True
End With
End If
End If
End If

It works when I have a label I want Hello to display in, cause the I just say:

.Caption = fld.Value

But I have a text box instead so I just don't know how I can get the text box
to equal Hello on the form. I can do it with the label and everything works
no problem, just need the text box.
Hope that clears things up a bit.
Thanks!
Hey there,
I have a control form in which I put a value in, lets say Hello
[quoted text clipped - 9 lines]
Please help, thanks!

I think something else is amiss.

First, try doing this:

Me.Controls("Text" & intCount) = intCount

This is to verify that the left hand works.

Other thing, you're setting ControlSource = fld.Value. You didn't
explain what is the fld and I'm not sure if it actually makes sense to
set ControlSource to a value of a field... Did you mean to set a field
to a controlsource? If so, it should be ControlSource = fld.Name

But more importantly.... why? There may be in fact a better solution
than dynamically assigning fields to controls at runtime. Indeed, you
could simply set Me.Recordeet = rst and all controls with the
controlsource set accordingly would then pick up the field with same
name as named in controlsource, making it a simple matter of binding a
recordset based on query with correct aliasing for all given columns ->
controls.
 
G

gmazza via AccessMonster.com

Anyone else have an opinion on this?
Everything works, and I do want the value of the field in my table, the value
being Hello.
I want Hello in my textbox on my form.
Here is my IF statement in the middle of my recordset on my On Open event:
If fld.Name = "CriteriaValue" Then
If IsNull(fld.Value) Then
Else
With Me.Controls("Text" & intCount)
.Caption = fld.Value
.Visible = True
.FontBold = True
End With

Else
intCount = intCount + 1
With Me.Controls("Text" & intCount)
Me.Controls("Text" & intCount).ControlSource = fld.Value
.FontBold = False
.Visible = True
End With
End If
End If
End If

It works when I have a label I want Hello to display in, cause the I just say:

.Caption = fld.Value

But I have a text box instead so I just don't know how I can get the text box
to equal Hello on the form. I can do it with the label and everything works
no problem, just need the text box.
Hope that clears things up a bit.
Thanks!
[quoted text clipped - 22 lines]
recordset based on query with correct aliasing for all given columns ->
controls.
 
G

GB

Well, not sure what it is exactly that you are trying to revise. Reviewing
forms I'm working on right now, the label is not id'd with the same "name" as
the text box, but rather identified as either labelX or NameOfTextBox_label.

That being said, .Caption works on the label itself, whereas if you want the
text box to contain the information you are looking for, use .Value = instead
of .Caption =.
Didn't test this within a with statement, but simply setting the control to
= your text works as well.

gmazza via AccessMonster.com said:
Anyone else have an opinion on this?
Everything works, and I do want the value of the field in my table, the value
being Hello.
I want Hello in my textbox on my form.
Here is my IF statement in the middle of my recordset on my On Open event:
If fld.Name = "CriteriaValue" Then
If IsNull(fld.Value) Then
Else
With Me.Controls("Text" & intCount)
.Caption = fld.Value
.Visible = True
.FontBold = True
End With

Else
intCount = intCount + 1
With Me.Controls("Text" & intCount)
Me.Controls("Text" & intCount).ControlSource = fld.Value
.FontBold = False
.Visible = True
End With
End If
End If
End If

It works when I have a label I want Hello to display in, cause the I just say:

.Caption = fld.Value

But I have a text box instead so I just don't know how I can get the text box
to equal Hello on the form. I can do it with the label and everything works
no problem, just need the text box.
Hope that clears things up a bit.
Thanks!
Hey there,
I have a control form in which I put a value in, lets say Hello
[quoted text clipped - 22 lines]
recordset based on query with correct aliasing for all given columns ->
controls.
 
G

gmazza via AccessMonster.com

I tried .Value and it didn't work, getting same error.
I can't just make the textbox = to my text because my text is from a table
within a recordset. So I go through my recordset and when I hit the
appropriate column, I want the data in that column to be displayed on a text
box on my form, I just can't get the syntax right which is why I keep getting
errors on that line.
Thanks for your reply.
Well, not sure what it is exactly that you are trying to revise. Reviewing
forms I'm working on right now, the label is not id'd with the same "name" as
the text box, but rather identified as either labelX or NameOfTextBox_label.

That being said, .Caption works on the label itself, whereas if you want the
text box to contain the information you are looking for, use .Value = instead
of .Caption =.
Didn't test this within a with statement, but simply setting the control to
= your text works as well.
Anyone else have an opinion on this?
[quoted text clipped - 37 lines]
 
G

GB

Well, the only other thing I can think of is that perhaps you need to type
cast your datatable value to a string, or you have something "squirrely" as a
result of fld.Value.

Have you tried using just "Hello" in place of fld.Value and it works, but
then with fld.Value you get the error? This Fld object, what data type is
it? Just an object?

So you tried:
If fld.Name = "CriteriaValue" Then
If IsNull(fld.Value) Then
Else
With Me.Controls("Text" & intCount)
.Value = fld.Value ' Change made here for text box
.Visible = True
.FontBold = True
End With

'whatever additional code that is between the end with (above) and the
following Else (Note that there is no end if statement before here, no
additional if statement for which the next Else applies, nor is there an
elseif above.)

Else
intCount = intCount + 1
With Me.Controls("Text" & intCount)
Me.Controls("Text" & intCount).ControlSource = fld.Value
.FontBold = False
.Visible = True
End With
End If
End If
End If

What about changing the following lines,
With Me.Controls("Text" & intCount)
.Value = fld.Value ' Change made here for text box
.Visible = True

to:
With Me.Controls("Text" & intCount)
.Value = cStr(fld.Value) ' Change made here for text box
.Visible = True

or stopping the code and using the watch window to identify what is going on
in object fld.

gmazza via AccessMonster.com said:
I tried .Value and it didn't work, getting same error.
I can't just make the textbox = to my text because my text is from a table
within a recordset. So I go through my recordset and when I hit the
appropriate column, I want the data in that column to be displayed on a text
box on my form, I just can't get the syntax right which is why I keep getting
errors on that line.
Thanks for your reply.
Well, not sure what it is exactly that you are trying to revise. Reviewing
forms I'm working on right now, the label is not id'd with the same "name" as
the text box, but rather identified as either labelX or NameOfTextBox_label.

That being said, .Caption works on the label itself, whereas if you want the
text box to contain the information you are looking for, use .Value = instead
of .Caption =.
Didn't test this within a with statement, but simply setting the control to
= your text works as well.
Anyone else have an opinion on this?
[quoted text clipped - 37 lines]
recordset based on query with correct aliasing for all given columns ->
controls.
 
G

gmazza via AccessMonster.com

Thanks for your reply GB.
I tried using "Hello" in place and same error.
The fld is being declared as:
Dim fld As DAO.Field
I also tried your suggestion:
Value = CStr(fld.Value) - same error
I debug and the value of fld.Value is "Hello" as that is what is in my table.
I just don't understand why I can't make my text box equal that.
It doesn't like .Value = fld.Value
It doesn't like: Me.Controls("Text" & intCount).ControlSource = fld.Value

So its not the fld.Value that is the problem, its finding the record and
passing it correctly, its trying to make it appear in the text box on my form
that is stifling me.


Well, the only other thing I can think of is that perhaps you need to type
cast your datatable value to a string, or you have something "squirrely" as a
result of fld.Value.

Have you tried using just "Hello" in place of fld.Value and it works, but
then with fld.Value you get the error? This Fld object, what data type is
it? Just an object?

So you tried:
If fld.Name = "CriteriaValue" Then
If IsNull(fld.Value) Then
Else
With Me.Controls("Text" & intCount)
.Value = fld.Value ' Change made here for text box
.Visible = True
.FontBold = True
End With

'whatever additional code that is between the end with (above) and the
following Else (Note that there is no end if statement before here, no
additional if statement for which the next Else applies, nor is there an
elseif above.)

Else
intCount = intCount + 1
With Me.Controls("Text" & intCount)
Me.Controls("Text" & intCount).ControlSource = fld.Value
.FontBold = False
.Visible = True
End With
End If
End If
End If

What about changing the following lines,
With Me.Controls("Text" & intCount)
.Value = fld.Value ' Change made here for text box
.Visible = True

to:
With Me.Controls("Text" & intCount)
.Value = cStr(fld.Value) ' Change made here for text box
.Visible = True

or stopping the code and using the watch window to identify what is going on
in object fld.
I tried .Value and it didn't work, getting same error.
I can't just make the textbox = to my text because my text is from a table
[quoted text clipped - 19 lines]
 
G

GB

So, it sounds like something about the object (control) on the form is the
problem. Have you confirmed that there is only one control with that name,
and that the control (text box) in which you are trying to show data is
actually a text box? It appears as you said that the correct data is getting
to the sub/function, but it is not being processed as expected when referring
to items on the form. You could also try to debug and determine the type of
control that you are referring. If you put a break somewhere in the
procedure and "WATCH" the Me.Controls("Text" & intcount) you should see also
what type of control is there, and also be able to see what values/data are
currently in it so that you can possibly narrow down which thing on the form
is being referred by that "Text" & intcount.

Basically it seems like some troubleshooting from here. As Banana basically
said, code looks fine, so must be something else.

gmazza via AccessMonster.com said:
Thanks for your reply GB.
I tried using "Hello" in place and same error.
The fld is being declared as:
Dim fld As DAO.Field
I also tried your suggestion:
.Value = CStr(fld.Value) - same error
I debug and the value of fld.Value is "Hello" as that is what is in my table.
I just don't understand why I can't make my text box equal that.
It doesn't like .Value = fld.Value
It doesn't like: Me.Controls("Text" & intCount).ControlSource = fld.Value

So its not the fld.Value that is the problem, its finding the record and
passing it correctly, its trying to make it appear in the text box on my form
that is stifling me.


Well, the only other thing I can think of is that perhaps you need to type
cast your datatable value to a string, or you have something "squirrely" as a
result of fld.Value.

Have you tried using just "Hello" in place of fld.Value and it works, but
then with fld.Value you get the error? This Fld object, what data type is
it? Just an object?

So you tried:
If fld.Name = "CriteriaValue" Then
If IsNull(fld.Value) Then
Else
With Me.Controls("Text" & intCount)
.Value = fld.Value ' Change made here for text box
.Visible = True
.FontBold = True
End With

'whatever additional code that is between the end with (above) and the
following Else (Note that there is no end if statement before here, no
additional if statement for which the next Else applies, nor is there an
elseif above.)

Else
intCount = intCount + 1
With Me.Controls("Text" & intCount)
Me.Controls("Text" & intCount).ControlSource = fld.Value
.FontBold = False
.Visible = True
End With
End If
End If
End If

What about changing the following lines,
With Me.Controls("Text" & intCount)
.Value = fld.Value ' Change made here for text box
.Visible = True

to:
With Me.Controls("Text" & intCount)
.Value = cStr(fld.Value) ' Change made here for text box
.Visible = True

or stopping the code and using the watch window to identify what is going on
in object fld.
I tried .Value and it didn't work, getting same error.
I can't just make the textbox = to my text because my text is from a table
[quoted text clipped - 19 lines]
recordset based on query with correct aliasing for all given columns ->
controls.
 

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