VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This function reads the idfield value out of any combobox. One code fits all.

by Per Janssen (3 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 19th January 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This function reads the idfield value out of any combobox. One code fits all.

Rate This function reads the idfield value out of any combobox. One code fits all.



' call the function LookupValue
TempID = LookupValue("SELECT Artist FROM Bands", "ArtistID", "cmbArtist", "Artist")


' the function LookupValue
Public Function LookupValue(SQLStatement As String, IDFieldname As String, Value As String, Fieldname As String)

Dim ado As ADODB.Connection
Dim rsTemp As ADODB.Recordset

Set ado = CreateObject("ADODB.Connection")
ado.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\CDCollectie.mdb;Persist Security Info=False"
    
Set rsTemp = CreateObject("adodb.recordset")
    With rsTemp
        .CursorType = adOpenDynamic
        .LockType = adLockBatchOptimistic
        .Open SQLStatement, ado
    End With
    ' if not excist, make a new record
    If rsTemp.EOF = True Then
        rsTemp.AddNew
            rsTemp(Fieldname) = Value
            rsTemp.UpdateBatch
            LookupValue = rsTemp(IDFieldname)
    Else
        Do While Not rsTemp.EOF
            LookupValue = rsTemp(IDFieldname)
            rsTemp.MoveNext
        Loop
    End If
    
rsTemp.Close
Set rsTemp = Nothing
  
ado.Close
Set ado = Nothing
        
End Function


Download this snippet    Add to My Saved Code

This function reads the idfield value out of any combobox. One code fits all. Comments

No comments have been posted about This function reads the idfield value out of any combobox. One code fits all.. Why not be the first to post a comment about This function reads the idfield value out of any combobox. One code fits all..

Post your comment

Subject:
Message:
0/1000 characters