Using select as button controlsource

  • Thread starter Thread starter Wendy
  • Start date Start date
W

Wendy

Hi

I want the button to fill a text box with the data from the table as
selected by which value is selected from the list box. It shows #Name? in
the text box Txtblvalues, and when I look at controlsource of the
Txtblvalues it does show the strSQL . I think it is a syntax error but, it
works fine in a query.

Thanks

Wendy

Public Sub btnGo_Click()
Dim TblName As String
Dim strSQL As String

If Me.LstBoxAC.Value = "NLC" Then TblName = "TblNLC"
If Me.LstBoxAC.Value = "HU" Then TblName = "TblHU"
strSQL = "SELECT TOP 1 [" & TblName

strSQL = strSQL & "].* FROM [" & TblName

strSQL = strSQL + "]"
Me.Txtblvalues.ControlSource = strSQL

End Sub
 
If I remember correctly you can't run a Select query from VBA, only action
queries such as Append, Update, etc.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
Can you give some ideas please as I don't know any? Using Access 2000
windows XP
Thanks

Wendy
 
Back
Top