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

SQL select into a recordset with a key

Status
Not open for further replies.

ToeJamNEarl

Programmer
Jan 26, 2004
91
US
Hey guys

How would I make it so that I can populate a table I make on the machine that I will have a key (used for ID of each record) associated with each record in the recordset?

Right now I am creating my recordset as follows:
Code:
Dim rsDataSFAF as Object
Set rsDataSFAF = New ADODB.Recordset 
        
strSQL = "SELECT ITEM_NUMBER , DESCRIPTION, TYPE FROM DBTABLE ORDER BY ITEM_NUMBER"

 rsDataSFAF.Open UCase$(Trim$(strSQL)), DBConnection, adOpenDynamic, adLockPessimistic

    'Move to beginning of the recordset
    rsDataSFAF.MoveFirst
    
    'Do while not at end of the recordset
    Do While Not rsDataSFAF.EOF

        cboPF.AddItem rsDataSFAF!ITEM_NUMBER & " - " & rsDataSFAF!Description
        
        rsDataSFAF.MoveNext ' Move to next record
    Loop
    
    rsDataSFAF.Close

DBConnection is already made the connection to the ORacle DB.

What it is doing here is performing an SQL select statement that grabs those fields and dumps it into a combobox that I have on my form.

I want to be able to make this recordset have a KEY associated with each record in the recordset. That way when the user clicks the item in the combobox I can have a reference to which value I need. There will be some other fields I grab from the Oracle table that will need this key to be associated with this recordset.

Hope someone understands this post. I will be happy to try to help clarify if there are any questions.

Thank you,

-Diran
 
You should create the key when adding the record to the database. Is ITEM_NUMBER a key field? If your record doesn't have a key field or a concatenated key field I don't see a away around your problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top