Assign Result from Search to Form

G

Guest

I've Access 2003 front end and SQL Server 2k backend. I create a blank
database and connect it to SQL Server via ODBC. What I'm trying to do is
create a form to allow the user to select a task from a combo box locate in
the form header section as a value to search for a record and if there is a
match, display the record in the form detail section. the combo box is based
on a task table. once the user selects a task, the query run against the task
table and if a match is found, display the record in the form detail section.
the combo box is working fine. however, when the user click the go button,
nothing return to the detail section. i check and the task select does exist
in the task table. i do not get a warning or error message. below is the
code behind the go button. what did i do wrong. your help/suggestion is
greatly appreciated. i've tried both select statements, neither one is
working. thanks

Private Sub cmdGo_Click()
Dim strMsg As String
Dim strSQL As String

If Len(Me!CboTaskCode) > 0 Then
strSQL = "SELECT * FROM dbo_tblTasks " & _
"WHERE TaskCode = " & Me!CboTaskCode

'strSQL = "SELECT * from dbo_tblTasks" & _
'"WHERE TaskCode = ' " & Me!CboTaskCode & " ' "
'Assign RecordSource and display Detail section
Me.RecordSource = strSQL
'Call DisplayDetail(True)
'Else
'strMsg = "Please select a valid task code"
'Hide Detail section
'Call DisplayDetail(False)
End If

If Len(strMsg) > 0 Then
MsgBox strMsg, , "Can't Display Task"
Me!CboTaskCode.SetFocus
'Call DisplayDetail(False)
End If
'resize form
DoCmd.RunCommand acCmdSizeToFitForm

End Sub
 

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