how to feed result from P_T query to combo box?

H

homer

I have this line of code working.
Form2 Form_load
currentdb.QueryDefs("qryPassthrough").SQL = "Exec INV_getParentItemBYID
" & Me.OpenArgs

I also have a combo box (cboParentItem) on Form2 that ties to the
qryPassthrough as its row source.

How should I run the P_T, then tie the returned values to the combo?
If I run
DoCmd.OpenQuery ("qryPassthrough")
cboParentItem.Requery
The result will open in its own grid.
With or without DoCmd, the combo would get data until the click event.

Also, if the P_T did not return any thing, I want to do something like this:
cboParentItem.RowSourceType = "Value List"
cboParentItem.ColumnWidths = "2 in;0 in"
cboParentItem.RowSource = "There is no parent info available"
cboParentItem.DefaultValue = "There is no parent info available"

how can I check the result of the P_T, then take action accordingly?

Thanks!
 
D

Duane Hookom

The P-T query is a query so just set the Row Source type to Table/Query and
set the Row Source to "qryPassthrough".
 
O

Ofer

One note, homer ask to check first if there are any records returned from the
PT, and if not to set a value list
 
O

Ofer

Try this

Dim MyRec as Recordset, MyDB as database
Set MyDB=Codedb
currentdb.QueryDefs("qryPassthrough").SQL = "Exec INV_getParentItemBYID
" & Me.OpenArgs

Set MyRec = MyDB.OpenRecordset ("qryPassthrough")
If MyRec.eof then
cboParentItem.RowSourceType = "Value List"
cboParentItem.ColumnWidths = "2 in"
cboParentItem.ColumnCount = 1
cboParentItem.RowSource = "There is no parent info available"
cboParentItem.DefaultValue = "There is no parent info available"
else
cboParentItem.RowSourceType = "Table/Query"
cboParentItem.ColumnWidths = "2 in;2 in"
cboParentItem.ColumnCount = 2
Me.ComboBoxName.RowSource = "Select Field1, Field2 From qryPassthrough"
end if

Change the columncount, width, row source to suit your needs
 
Top