ADO - Add Item to combo box

R

Raul Sousa

I use to work with DAO, now I want to start working with
ADO.

I have this code to add a new item to a combo box.

Dim db As DAO.Database
Dim RS As DAO.Recordset
Dim strMsg As String

strMsg = "Bla bla bla"

If MsgBox(strMsg, vbQuestion + vbYesNo, "Field
unknow") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set RS = db.OpenRecordset("Table", dbOpenDynaset)
RS.AddNew
RS.Fields("Field") = NewData
RS.Update
RS.Close
Response = acDataErrAdded
End If

Now with ADO I can't make it work. I don't know which
string connection should I use. The one bellow I toke
from an example in vba help.
Can anyone help me here?


Dim RS As New ADODB.Recordset
Dim strMsg As String
Dim Cnxn As New ADODB.Connection
Dim strCnxn As String

strCnxn = "Provider='sqloledb';Data
Source='MySqlServer';" & _
"Initial Catalog='Northwind';Integrated
Security='SSPI';"

Cnxn.Open strCnxn


strMsg = "bla bla bla"

If MsgBox(strMsg, vbQuestion + vbYesNo, "Field
unknow") = vbNo Then
Response = acDataErrContinue
Else
RS.Open "TipoConcorrentes"
("Field") = NewData
RS.Update
RS.Close
Response = acDataErrAdded
 
T

Tim Ferguson

RS.AddNew
RS.Fields("Field") = NewData
RS.Update


This would be something like

strSQL = "INSERT INTO Table (Field) " & vbCrLf & _
"VALUES (" & Quoted(NewData) & ")"

conn.Execute strSQL, etc, etc

.... mind you, it would have looked quite like that in DAO as well.

HTH

Tim F
 

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