Creating text box name based on rs.fields(x).name 
Author Message
 Creating text box name based on rs.fields(x).name

Something simple but Iv gone brain dead.

I need to create a large number of text box names on the fly based on a
fields name in a database.  These already being on the form, so the name is
know.

e.g.
    txtID.Text = Rs.Fields("ID") or can be txtID.Text = Rs.Fields("0")
    txtBRNRef.Text = Rs.Fields("BRNRef") or can be txtID.Text =
Rs.Fields("1")

Using this, the field name can be easily returned:

    rs.fields(x).name  which will return the name of the field x

Thus in effect I want to achive this sort of result.  Do you know of a way
around this?

    txt + (rs.fields(x).name) . text  =  Rs . Fields("x")       so if field
name is ID, then the above to return   txtID.txt

Creating a string with a value of ' txtID.txt ' is not a problem but turning
its 'value' into a 'text box name' Im not sure about.  Maybe this is the
route?

Using standard option, if the field is null value, it will of course return
error.  Don't want to do the boring need to check every field for nulls
first. Using naming on the fly approach, I can easily check cos its name
will be created based on the field name and checked for null in a loop.

Any thoughts?
Thanks
Dave



Tue, 07 Sep 2004 21:47:52 GMT  
 Creating text box name based on rs.fields(x).name

Quote:
> Creating a string with a value of ' txtID.txt ' is not a problem but
turning
> its 'value' into a 'text box name' Im not sure about.  Maybe this is the
> route?

How about this:

dim c as control

for each c in myform
    if typename(c) = "TextBox" and c.name = "myfield" then
        ...
    end if
next c

Martin



Tue, 07 Sep 2004 22:04:26 GMT  
 Creating text box name based on rs.fields(x).name
Hi Martin,

Have tweaked as per and it works fine.

dim ctl as control

for each ctl in form.controls
    if typeof ctl is textbox then
        if ctl.name = "tx" & rs.fields(x).name then
            ctl.text = rs.fields(x).value
        endif
    endif
next

Thanks.
Dave


Quote:
> > Creating a string with a value of ' txtID.txt ' is not a problem but
> turning
> > its 'value' into a 'text box name' Im not sure about.  Maybe this is the
> > route?

> How about this:

> dim c as control

> for each c in myform
>     if typename(c) = "TextBox" and c.name = "myfield" then
>         ...
>     end if
> next c

> Martin



Tue, 07 Sep 2004 22:17:01 GMT  
 Creating text box name based on rs.fields(x).name

Quote:
> Thanks.
> Dave

My pleasure.

Martin



Tue, 07 Sep 2004 23:31:42 GMT  
 Creating text box name based on rs.fields(x).name
Alternatively

Me.Controls("tx" & rs.Fields(x).Name).Text = rs.fields(x).value

Ian Williams



Quote:
> Hi Martin,

> Have tweaked as per and it works fine.

> dim ctl as control

> for each ctl in form.controls
>     if typeof ctl is textbox then
>         if ctl.name = "tx" & rs.fields(x).name then
>             ctl.text = rs.fields(x).value
>         endif
>     endif
> next

> Thanks.
> Dave



Wed, 08 Sep 2004 00:23:40 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Creating text box name based on rs.fields(x).name

2. Numeric Index of RS.field from field name?

3. using rs field names

4. ADO: format rs!xxxxx when the field name exists in more than one table

5. Reading file name from text box and/or File List Box

6. How do I parse name into first and last name fields

7. A SELECT statement on a name field with an apostrophe in the name

8. Obtaining table names/field names from Access @ runtime

9. OMR Marks (Text box filled with underscore based on populated fields in mailmerge)

10. rs!field vs. rs.fields(fieldname).value

11. Obtaining Field Names into Combo Box

12. Text field parsing on a name

 

 
Powered by phpBB® Forum Software