Scott Heslop
Registered User.
- Local time
- Today, 22:59
- Joined
- Aug 29, 2012
- Messages
- 17
Hi,
Ive just recently changed my database from a *.MDB to a *.ACCDB. Once i done this my ''New ADODB Recordet" no longer exists. and i ashume i need to use a DAO recordset. I need to add a new record and make the employeeId to + 1. Here is my code i had with the ADODB recordset. Can someone provide me with the code for doing the same job but from a DAO recordet? It usually gets stuck when i reach the code in bold. Any suggestions?
:banghead:
Private Sub AddNewRecordAndDisplayIt()
Dim vMaxRecNo As Variant
Dim MySQL As String
Dim CurrRec As New ADODB.Recordset
Me.AllowAdditions = True
'Find current max rec no.
vMaxRecNo = DMax("nEmployeeID", "EmployeeDetails")
If IsNull(vMaxRecNo) Then
nCurrRecID = 1
Else
nCurrRecID = vMaxRecNo + 1
End If
With CurrRec
.Open "EmployeeDetails", CurrentProject.Connection, adOpenStatic, adLockPessimistic
.AddNew
!nEmployeeID = nCurrRecID 'Primary Key
.Update
.Close
End With
Set CurrRec = Nothing
Me.AllowAdditions = False
'Display the new record.
MySQL = "SELECT a.* From EmployeeDetails a where a.nEmployeeID =" & nCurrRecID
Me.RecordSource = MySQL
End Sub
Ive just recently changed my database from a *.MDB to a *.ACCDB. Once i done this my ''New ADODB Recordet" no longer exists. and i ashume i need to use a DAO recordset. I need to add a new record and make the employeeId to + 1. Here is my code i had with the ADODB recordset. Can someone provide me with the code for doing the same job but from a DAO recordet? It usually gets stuck when i reach the code in bold. Any suggestions?
:banghead:
Private Sub AddNewRecordAndDisplayIt()
Dim vMaxRecNo As Variant
Dim MySQL As String
Dim CurrRec As New ADODB.Recordset
Me.AllowAdditions = True
'Find current max rec no.
vMaxRecNo = DMax("nEmployeeID", "EmployeeDetails")
If IsNull(vMaxRecNo) Then
nCurrRecID = 1
Else
nCurrRecID = vMaxRecNo + 1
End If
With CurrRec
.Open "EmployeeDetails", CurrentProject.Connection, adOpenStatic, adLockPessimistic
.AddNew
!nEmployeeID = nCurrRecID 'Primary Key
.Update
.Close
End With
Set CurrRec = Nothing
Me.AllowAdditions = False
'Display the new record.
MySQL = "SELECT a.* From EmployeeDetails a where a.nEmployeeID =" & nCurrRecID
Me.RecordSource = MySQL
End Sub