Att Peter Walker Re ComboBox Question

B

Brian

Hi Peter,
Thank you for the info listed below, it worked fine. But now I have a
poublem.

I set up a new db with more tables and a nine tab form, one tab for each
recipe catagory, ie, Appatizers-Beverages = tbl01AppBev, etc. I now have the
following set up. (I'm just using table01 and tab01 (form) to test this
stuff.

TABLE = tbl01AppBev
FIELDS
RecID, RecType, Ingrediant, RecipeName, RecipeNote

I'm running a query (qry01AppBev) Fields
RecID, RecType, Ingrediants, RecipeName
Criteria for Type - Like [Forms]![KATHYS RECIPES]![cbo01Ab]
Criteria for Ingrediant - Like [Forms]![KATHYS RECIPES]![cbo02Ab]

FORM
Form Name = KATHYS RECIPES
Number of Tabs = 9
First Tab = tab01AppBev
Has the following controls:

Cbox=cbo01Ab (Type), which gets its info from
Row Source Type = Table/Query
Row Source =
SELECT DISTINCT tbl01AppBev.RecType
FROM tbl01AppBev
ORDER BY tbl01AppBeve.RecType

Cbox=cbo02Ab (Ingredient), which gets its info from qry01AppBev
Row Source Type = Table/Query
Row Source =
SELECT DISTINCT qryl01AppBev.Ingredients
FROM qry01AppBev

Cbox = cbo03Ab (Recipe Name), which gets its info from qry01AppBev
Row Source Type = Table/Query
Row Source =
SELECT DISTINCT qryl01AppBev.RecipeName
FROM qry01AppBev

Txtbox = txt01Ab (Recipe Notes), which needs to get its info from
tbl01AppBev, based on the current selection in cbo03AppBev

Using your code, below, I don't understand how the textbox gets the
RecipeNote.

I copied and pasted the code into the new cbo03 AfterUpdate and changed the
values to reflect the new form, but I'm getting an error.

Runtime error 3061
too few perameters. Expected 1
(what perameters am I missing?)
MY NEW CODE
Private Sub cbo03Ab_AfterUpdate()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()

If Nz(Me.cbo03Ab, "") <> "" Then
Set rst = db.OpenRecordset _
( _
"SELECT RecipeNote " & _
"FROM tbl01AppBev " & _
"WHERE RecID = " & cbo03Ab _
)
'If we have indeed have data
If Not (rst.EOF And rst.BOF) Then
RecipeNote = rst!RecipeNote
End If ' (EOF / BOF test)
End If ' (Null / empty test)
End Sub

I'm sorry for being so long winded, but maybe someone else will read this
and get some understanding.
Thank you for any help,
Brian

YOUR ORIGINAL CODE
Private Sub cbo03RecNam_AfterUpdate()
'///////////////////////////////////
'We use a recordset to retrieve the memo
'column data as display that in a text box.
'The SQL used returns the record based on the
'numeric surrogate key 'RecID'
'We test for nulls because the operator may
'backspace out text in the cbo resulting in
'a null being passed in the SQL. I also use
'the NZ because to fend off some wierd
'situation in future versions (whatever) where
'it may be possible to read a empty string.
'///////////////////////////////////

Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()

If Nz(Me.cbo03RecNam, "") <> "" Then
Set rst = db.OpenRecordset _
( _
"SELECT Recipe " & _
"FROM Recipes " & _
"WHERE RecID = " & cbo03RecNam _
)
'If we have indeed have data
If Not (rst.EOF And rst.BOF) Then
Recipe = rst!Recipe
End If ' (EOF / BOF test)
End If ' (Null / empty test)
End Sub


See
www.papwalker.com/public/recipehelp.mdb
--

peter walker MVP

Please post replies to the news group so everyone can benefit.
www.papwalker.com
 

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