Dim dsRecordSet As ADODB.Recordset
Dim cmdAuctioneer As ADODB.Command
Dim sSQL As String
Set dsRecordSet = New ADODB.Recordset
Set cmdAuctioneer = New ADODB.Command
On Error Resume Next
dsRecordSet.Open "tblAuctioneers", CurrentProject.Connection, adOpenStatic, adLockOptimistic
If Err.Number <> "" Then
MsgBox "Error " & Err.Description, vbInformation, "Error"
Exit Sub
End If
On Error Resume Next
dsRecordSet.MoveLast
sAucID = dsRecordSet.Fields("Auc_ID")
If sAucID = "" Then
sAucID = "A100001"
Else
sAucID = "A" & Right(sAucID, 6) + 1
End If
Me.txtAucID.Value = sAucID
Set dsRecordSet = New ADODB.Recordset
'Insert Record
sSQL = "Insert into tblAuctioneers values(" & _
"'" & sAucID & "', " & _
"'" & Me.txtAucName.Value & "', " & _
"'" & Me.txtAucCode.Value & "', " & _
"'" & Me.txtAucCode.Value & "'); "
cmdAuctioneer.CommandText = sSQL
cmdAuctioneer.CommandType = adCmdText
cmdAuctioneer.ActiveConnection = CurrentProject.Connection
Set dsRecordSet = cmdAuctioneer.Execute
dsRecordSet.Close
Set cmdAuctioneer = Nothing
Set dsRecordSet = Nothing
Me.cmdSave.Enabled = True
'Clear textbox
Me.txtAucID = ""
Me.txtAucName = ""
Me.txtAucCode = ""
I try to use the following recordset to insert record to the table at first, but it doens't work. so i try the above code to do it
Do you have any idea?? Oh ya. I'm using access 2000
With dsRecordSet
.AddNew
.Fields("Auc_ID") = sAucID
.Fields("Auc_Name") = Me.txtAucName.Value
.Fields("Auc_Code") = Me.txtAucCode.Value
.Update
End With