sacacompany
Member
- Local time
- Today, 22:59
- Joined
- Dec 28, 2022
- Messages
- 31
Hi I m using the following VBA to add/update/delete records in the table on my SQL server but getting errors on Records. update....Record update run time error3146 ODBC Call Failed
Private Sub Command43_Click()
Dim Records As DAO.Recordset
Dim Records1 As DAO.Recordset
Dim Records2 As DAO.Recordset
'Dim Records3 As DAO.Recordset
Dim dd1 As Date
Dim dd As Date
Dim ssql As String
Dim stax As Variant
Dim RentID As Variant
Dim ERate As Variant
RentID = DLookup("[id]", "[rentagreement]", "[ID] =" & Forms![RentInvoicingGenenration]!RID)
'Set Records2 = CurrentDb.OpenRecordset("select id from rentagreement", dbOpenDynaset, dbAppendOnly)
'Records2.FindFirst "id= '" & Me.RID '"
If RentID > 0 Then
DoCmd.RunSQL "delete * from rentinvoice where rentagreementid = " _
& "Forms![RentInvoicingGenenration]!RID;"
GoTo GenerateInvoice
Else
GoTo GenerateInvoice
End If
GenerateInvoice:
dd = Me!DATEFROM.Value
Set Records = CurrentDb.OpenRecordset("Select * From rentinvoice", dbOpenDynaset, dbAppendOnly)
'Set Records1 = CurrentDb.OpenRecordset("Select salestaxrate " _
& "From tenant " _
& "where (id = " & Forms!Rentinvoicing!Text33 & ") ", dbOpenDynaset, dbAppendOnly)
'STax = DLookup("", "tenant", "id= & Forms![rentinvoicing]![Text33] & ")
stax = DLookup("[salestaxrate]", "[Tenant]", "[ID] =" & Forms![RentInvoicingGenenration]!Text33)
Do While dd <= Me!DATETO.Value
dd1 = DateSerial(Year(dd), Month(dd) + 1, 0)
Records.AddNew
Records!InvNo.Value = dd
Records!Dated.Value = dd
Records!RENTAGREEMENTID.Value = Me!RID.Value ' ?: Me!ID.Value
Records!DATEFROM.Value = dd
Records!DATETO.Value = dd1
Records!AREA.Value = Me!AREASQFT.Value
Records!RENTPERMONTH.Value = Me!mrent.Value
Records!SalesTaxRate.Value = stax
Records!SecurityCharges.Value = Me!Text44.Value
Records!AntenaCharges.Value = Me!antena.Value
'Records!ElectricRate.Value = Me!Text48.Value
Records.Update
dd = DateAdd("d", 1, dd1)
Loop
Set Records = Nothing
MsgBox "Rent Invoices for the period from &dd& to #dd1# Generated Successfully!"
End Sub
Private Sub Command43_Click()
Dim Records As DAO.Recordset
Dim Records1 As DAO.Recordset
Dim Records2 As DAO.Recordset
'Dim Records3 As DAO.Recordset
Dim dd1 As Date
Dim dd As Date
Dim ssql As String
Dim stax As Variant
Dim RentID As Variant
Dim ERate As Variant
RentID = DLookup("[id]", "[rentagreement]", "[ID] =" & Forms![RentInvoicingGenenration]!RID)
'Set Records2 = CurrentDb.OpenRecordset("select id from rentagreement", dbOpenDynaset, dbAppendOnly)
'Records2.FindFirst "id= '" & Me.RID '"
If RentID > 0 Then
DoCmd.RunSQL "delete * from rentinvoice where rentagreementid = " _
& "Forms![RentInvoicingGenenration]!RID;"
GoTo GenerateInvoice
Else
GoTo GenerateInvoice
End If
GenerateInvoice:
dd = Me!DATEFROM.Value
Set Records = CurrentDb.OpenRecordset("Select * From rentinvoice", dbOpenDynaset, dbAppendOnly)
'Set Records1 = CurrentDb.OpenRecordset("Select salestaxrate " _
& "From tenant " _
& "where (id = " & Forms!Rentinvoicing!Text33 & ") ", dbOpenDynaset, dbAppendOnly)
'STax = DLookup("", "tenant", "id= & Forms![rentinvoicing]![Text33] & ")
stax = DLookup("[salestaxrate]", "[Tenant]", "[ID] =" & Forms![RentInvoicingGenenration]!Text33)
Do While dd <= Me!DATETO.Value
dd1 = DateSerial(Year(dd), Month(dd) + 1, 0)
Records.AddNew
Records!InvNo.Value = dd
Records!Dated.Value = dd
Records!RENTAGREEMENTID.Value = Me!RID.Value ' ?: Me!ID.Value
Records!DATEFROM.Value = dd
Records!DATETO.Value = dd1
Records!AREA.Value = Me!AREASQFT.Value
Records!RENTPERMONTH.Value = Me!mrent.Value
Records!SalesTaxRate.Value = stax
Records!SecurityCharges.Value = Me!Text44.Value
Records!AntenaCharges.Value = Me!antena.Value
'Records!ElectricRate.Value = Me!Text48.Value
Records.Update
dd = DateAdd("d", 1, dd1)
Loop
Set Records = Nothing
MsgBox "Rent Invoices for the period from &dd& to #dd1# Generated Successfully!"
End Sub