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!

COMMAND TEXT NOT SET 2

Status
Not open for further replies.

rry2k

Programmer
Jun 28, 2001
678
US
Hi,
I'm trying to use a dbcombo box as a driver for my form. With alot of help from Woyler I got everything setup but now I have another problem.

When I get to the line that opens the recordset (rs.open) I get the following error: command text not set for the command object.

Private Sub DBCombo1_Click(Area As Integer)
Dim sMyCriteria As String
Dim sSQL As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sDatabasePath As String
Set cn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
cn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=f:\db1.mdb;Uid=Admin;Pwd=;"
cn.Open
rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic, adCmdText
sMyCriteria = DBCombo1.Text
sSQL = "SELECT * FROM EMPLOYEES WHERE [name]='" & sMyCriteria & "'"
Text1.Text = rs("Name")
Text2.Text = rs("Title")
Text3.Text = rs("Department")
rs.Close
Set rs = Nothing
End Sub

Thanks for the help..Russ

 
The line :

sSQL = "SELECT * FROM EMPLOYEES WHERE [name]='" & sMyCriteria & "'"

needs to be before the line :

rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic, adCmdText

Hope this helps,

Dan.
 
Dan,
That got me down to the line where I populate text1 then I get eof or bof is true error. I'm not even getting to select a name from the combobox. is the event wrong?
 
what about the line :

sMyCriteria = DBCombo1.Text

this should still be the line direcly above the line :

sSQL = "SELECT * FROM EMPLOYEES WHERE [name]='" & sMyCriteria & "'"

so what you should have is :

Private Sub DBCombo1_Click(Area As Integer)
Dim sMyCriteria As String
Dim sSQL As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sDatabasePath As String
Set cn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
sMyCriteria = DBCombo1.Text
sSQL = "SELECT * FROM EMPLOYEES WHERE [name]='" & sMyCriteria & "'"
cn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=f:\db1.mdb;Uid=Admin;Pwd=;"
cn.Open
rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic, adCmdText
Text1.Text = rs("Name")
Text2.Text = rs("Title")
Text3.Text = rs("Department")
rs.Close
Set rs = Nothing
End Sub

The event should be fine. It would be worth checking that the recordset is not empty before trying to populate the text boxes, as the error you got that time means that no matching records have been returned.

Dan.
 
Use a regular combo box control. The need for the dbCombo is not necessary in this case
 
Thinking about it, perhaps this code should be in combo1_change and not click. This would show the list, but it would fire if you type in the combo, so it depends what functionality you are after.

Dan.
 
the change event will fire every time you type a character. That will cause you some headaches unless you test the changes as they come in.
 
I changed to a regular combo and now nothing happens. I put the code in combo_change and click, put a break point in both and I don't get to either?? very strange
 
no, it's empty but when I check the table directly it is indeed loaded.
 
Okay I have just checked and I admit the click event is definately better for this !
 
I'm really missing something here. I created a new app, put on a combo box, put a break on the click event and I never get to the break after I click on the combo?? I'm missing something stupid here.
 
I used a DropDown event and now I'm back to the combo not being populated. I tried combo1.addItem but that didn't help

Russ
 
The click event will not fire until there is an item to select in the combo box.
 
Danny and Woyler,
We/I finally got it. I Really appreciate the help.
I ended up loading the comboBox in the drop down event and then populating the text boxes on click.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top