For the first issue, I use code something like this, taking values from the form:
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim stUID As String
Dim stPWD As String
Dim sValue1 As String
Dim sValue2 As String
stUID = "User"
stPWD = "********"
sValue1 = Me.txtTextControl
sValue2 = Me.SomeOtherControl
Set cnn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cnn.Open "DSN=WPM;", stUID, stPWD
rs.CursorLocation = 3
rs.Open "SELECT * FROM tblSQLTable", cnn, 3, 3
rs.AddNew
rs("FieldName1") = sValue1
rs("FieldName2") = sValue2
...
rs.Update
rs.Close
cnn.Close
As to the second issue, I generally let SQL supply the autonumber by setting the PK field to Identity, and giving it a starting number 1, seed 1. If you can't do this, and you are not worried about errors, then you can create a view on the PK of the table, and set it to order DESC, and SELECT TOP 1. Then take that value and add one to it before updating the table. I would use a view instead of a pass-through query since SQL will optimize the view, but not the query.
Did that help?
mmcdonal
|