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

Form Field part of SQL Query Source?

Status
Not open for further replies.

misscrf

Technical User
Jun 7, 2004
1,344
US
I want to use SQL statement in VB to set the value for a field on a form, and part of that SQL statement is 2 other form fields that have been filled out.

User fills out server name and datbase name.

Then third field is to update with the location of the database file.

Something like this?
Code:
Private Sub txtDatabaseName_AfterUpdate()
Me.txtDatabaseLocation = "Select filename from " & "SELECT tblServerName.txtServerName FROM tblServerName WHERE (((tblServerName.PKServerNameID)=[Forms]![frmProject]![FKServerName])); " & ".master.dbo.sysdatabases " _
& "WHERE name = me.txtDatabaseName"
End Sub

Right now, after I update that 2nd field the 3rd is just filling with this actual statement. Not the results. Is it my syntax or my approach? Any suggestions, please?

misscrf

It is never too late to become what you could have been ~ George Eliot
 

The statement you have after Me.txtDatabaseLocation = is in the FORM of a query, but cannot be executed the way you show it.
I would create the query and use a dlookup to obtain the value.


Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top