Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

set combobox to display newly added record

$
0
0
my set-up is an Access front end linking to an sql server instance. I am trying to work out how to set the value of a combobox to the newly added record in the rowsource table. users will do this if the ethnicity they want to select is not in the rowsource of the combobox. here is the code I have so far:

Code:

Private Sub btnAddEthnicityOther_Click()
Dim strCat As String
Dim strCatSet As String
Dim rst As Recordset
Dim i As Integer


  If MsgBox("Do you want to add a new Other category to the Ethnicity Other drop down list?", vbYesNo + vbInformation) _
        = vbYes Then
        strCat = InputBox("Enter the new ethnicity name.")
        strCatSet = strCat
        If strCat <> "" Then
              Set rst = CurrentDb.OpenRecordset("dbo_tbllEthnicityOther", dbOpenDynaset, dbSeeChanges)
                rst.AddNew
                rst!EthOther = strCat
                rst.Update
                Set rst = Nothing
        End If
       
    i = "SELECT dbo_tbllEthnicityOther.EthOtherID FROM dbo_tbllEthnicityOther WHERE dbo_tbllEthnicityOther.EthOther like (" ' & strCatSet & '") "
    Me.cmbEthnicityOtherType.Requery
    Me.cmbEthnicityOtherType = Nz(i, 200)
End If
End Sub

the ethnicity other table has one identity column and a text column. I get a type mismatch on the i="sql statement" line. I'm cleary am missing something basic about passing sql results to a variable. Any help very much appriciated. Thanx.

Viewing all articles
Browse latest Browse all 13329

Trending Articles