Problem getting value from table and putting the value into a text

K

Keith

Hello,

In Textbox 32, of my form, I need to pt in the value Selected_Year which is
in the first row of table t_Parameters1
The table is not bound to the form . I wrote the code below and put it into
the Form, Load subroutine where it does not work. What do I need to do to
make this work and show the value?

Thank you,

Keith

The code follows

Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("t_Parameters1")


rst.MoveFirst

temp = rst!Selected_year ' this shows the value

Me.Text32.Text = rst!Selected_year ' this does not work, but it is
what I want to do

rst.Close


' Stop
 
R

Ron Weiner

You are working to hard. See if this one line of code does what you wanted.

Text32.Value = Dlookup("Selected_year", "t_Parameters1")
 
K

Klatuu

= DLookup("[Selected_year]", "t_Parameters1")

If Textbox32 is bound to a field in the form's record source, then put the
above in the Default Value property of the control.
If it is not bound and only there for display, put it in the Control Source
Property.
 
K

Keith

Klatuu
This worked great. Thank you.
I appreciate having both solutions to the problem.
Keith

Klatuu said:
= DLookup("[Selected_year]", "t_Parameters1")

If Textbox32 is bound to a field in the form's record source, then put the
above in the Default Value property of the control.
If it is not bound and only there for display, put it in the Control Source
Property.


Keith said:
Hello,

In Textbox 32, of my form, I need to pt in the value Selected_Year which is
in the first row of table t_Parameters1
The table is not bound to the form . I wrote the code below and put it into
the Form, Load subroutine where it does not work. What do I need to do to
make this work and show the value?

Thank you,

Keith

The code follows

Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("t_Parameters1")


rst.MoveFirst

temp = rst!Selected_year ' this shows the value

Me.Text32.Text = rst!Selected_year ' this does not work, but it is
what I want to do

rst.Close


' Stop
 

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