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

Combo Box to populate Text Box on same Access Form

Status
Not open for further replies.

aprilmarie

Technical User
Apr 17, 2002
4
US
Private Sub cboPlant_Change()

Dim dbs As Database
Dim rst As Recordset
Dim strSQL As String
Dim strPlant As String

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

strPlant = vbNullString
strSQL = vbNullString

Me.cboPlant.SetFocus

strPlant = Me.cboPlant.Text
strSQL = "SELECT Program FROM Plants WHERE Plant = " & strPlant & ";"

rst.MoveFirst
Do While Not rst.EOF
rst.MoveNext
Loop

txtProgram.SetFocus
Me.txtProgram.Value = strSQL

rst.Close
dbs.Close
End Sub

What is wrong with this?
 
Not sure what problem you are having aprilmarie but on a long shot, if you are getting a Mismatch Error and or expecting "Program" info to show up the textbox then:


Private Sub cboPlant_Change()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strPlant As String
Dim strProgram As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Plants")
strPlant = vbNullString
strSQL = vbNullString
strProgram = vbNullString
Me.cboPlant.SetFocus
strPlant = Me.cboPlant.Text
strSQL = "SELECT Program FROM Plants WHERE Plant = " & strPlant & ";"
rst.MoveFirst
Do While Not rst.EOF
strProgram = strProgram & rst.Fields("Program").Value
rst.MoveNext
Loop
txtProgram.SetFocus
Me.txtProgram.Value = strProgram
rst.Close
dbs.Close
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top