Hi guys
I got Syntax error when running that code:
Code:
Private Sub AddTenants_Click()
Dim strInsert As String
strInsert = "Insert into Tenants ( T_Name, Nationality, Employer, Lease_Date, U_ID, Rent, Phone)" & _
" Values ( '" & Me.Name & " ', '" & Me.Nationality & "', '" & Me.Employer & "', '" & Me.Lease_Date & "', " & Me.U_ID & ", " & _
Me.Current_Rent & ", '" Me.Phone "')"
CurrentDb.Execute (strInsert)
Dim New_T_ID As dao.Recordset
Set New_T_ID = CurrentDb.OpenRecoedSet("select @@identity")
CurrentDb.Execute "UPDATE Units SET Current_Tenant=" & New_T_ID &, Current_Rent= " & Me.Rent & " WHERE U_ID= " & Me.U_ID & " ;"
End Sub
All the date taken from fields in the form. I press the add new record button to execute that code. Then get the last inserted id to use it in another update query.
There is auto increment id in the Tenants table, I didn't add it to the statement to allow database to generate one, not sure if that is wrong in access DB.
I am working on the latest version of MS access
Thank you guys