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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Defult Value of Text Box

Status
Not open for further replies.

davetek

Programmer
Oct 30, 2002
42
IE
hey,

I want to put the default value of a text box equal to the result of a query...
in the default value of the text field i have
=[Query1]![Name1]

it keeps returning #Name? however....

anyone...
 
Unfortunately its more complicated than that.
A text box want a particular item or field not a recordset which is what a query is.

Dim Conn2 As ADODB.Connection
Dim Rs1 As ADODB.Recordset
Dim SQLCode As String
Set Conn2 = CurrentProject.Connection ' <<<<Note same as CurrentDb
Set Rs1 = New ADODB.Recordset
' SQLCode is where your Query statement will go such as below
SQLCode = &quot;SELECT * FROM [yourTable] WHERE Yourfield = something;&quot;
Rs1.Open SQLCode, Conn2, adOpenStatic, adLockOptimistic
'Then you can set the Texbox to any field in the query
Me![YourTextbox] = Rs1!AnyfieldInQueryStatement

' close it this way
Set Rs1 = Nothing
Set Conn2 = Nothing


DougP, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top