I've been looking for the solution for my problem in the forums but could'nt find what I need. I've read some posts where many of you answer that we should not try to store calculated values in tables but...
Here what I'm trying to do.
I've a table where I store some recurrent billings like let's say insurance, water, electricity, phone expenses, etc. Those come always at a recurrent date with an expected value. I've set up a form so I can see the records already in the table and insert new ones manually. Now, I want to be able to set up a report where I can see all the expenses for the next year (or whatever interval of time I choose) for that I would like from, let's say this month phone bill to create automatically the next twelve months already populated with dates, values, etc.
So when the bill comes we'll only have to insert some data (Ref. number, etc.) and change the status from let's say "expected" to "paid"
I've created a button on the form that runs a procedure that will ask how many records I want to append to the table
Some values are not to be changed so I do something like:
rst![Documento] = Doc
and there is no problem but when I try
rst![Data Início] = DateAdd(m, nPer, StartDate)
where StartDate = Me.Data Início (input from the form)
I get "Run-time error '5': Invalid procedure call or argument"
Probably the code doesn't look so well for experienced programmers but shouldn't it work?
Thanks for your help.
Code:
Private Sub Orçamentar_Click()
Dim db As DAO.Database, rst As DAO.Recordset
Dim i As Integer, StartDate As Date, EndDate As Date, EmDate As Date, VenDate As Date, nRegistos As Integer
Dim Seg As String, Doc As String, nDoc As String, Val As Currency, Sit As String, Per As String, nPer As Integer
' Point to this database
Set db = CurrentDb
' Open a recordset on the table
Set rst = db.OpenRecordset("Fidelidade Mundial", dbOpenDynaset, dbAppendOnly)
'Ask for input How many records do you want to create
nRegistos = InputBox("Quantos registos quer criar", "My Inputbox")
'Grab the data off the form
Seg = Me.Seguro
Doc = Me.Documento
nDoc = ""
StartDate = Me.Data_Início
EndDate = Me.Data_Fim
EmDate = Me.Data_de_Emissão
VenDate = Me.Data_Vencimento
Val = Me.Valor_a_Pagar
Sit = "Orçamentado"
Per = Me.Periodicidade
If Per = "Mensal" Then nPer = 1
If Per = "Bimensal" Then nPer = 2
If Per = "Trimestral" Then nPer = 3
If Per = "Semestral" Then nPer = 6
If Per = "Anual" Then nPer = 12
'Loop to add records
For i = 1 To nRegistos
'Add a new record
rst.AddNew
'Populate the fields of the new record
rst![Seguro] = Seg
rst![Documento] = Doc
rst![Data Início] = DateAdd(m, nPer, StartDate)
rst![Data Fim] = DateAdd(Dateinterval.Month, nPer, EndDate)
rst![Data de Emissão] = DateAdd(Dateinterval.Month, nPer, EmDate)
rst![Data Vencimento] = DateAdd(Dateinterval.Month, nPer, VenDate)
rst![Situação] = Sit
rst![Periodicidade] = Per
rst.Update
rst.Close
nPer = nPer * i
Next
Set rst = Nothing
Set db = Nothing
End Sub
Here what I'm trying to do.
I've a table where I store some recurrent billings like let's say insurance, water, electricity, phone expenses, etc. Those come always at a recurrent date with an expected value. I've set up a form so I can see the records already in the table and insert new ones manually. Now, I want to be able to set up a report where I can see all the expenses for the next year (or whatever interval of time I choose) for that I would like from, let's say this month phone bill to create automatically the next twelve months already populated with dates, values, etc.
So when the bill comes we'll only have to insert some data (Ref. number, etc.) and change the status from let's say "expected" to "paid"
I've created a button on the form that runs a procedure that will ask how many records I want to append to the table
Some values are not to be changed so I do something like:
rst![Documento] = Doc
and there is no problem but when I try
rst![Data Início] = DateAdd(m, nPer, StartDate)
where StartDate = Me.Data Início (input from the form)
I get "Run-time error '5': Invalid procedure call or argument"
Probably the code doesn't look so well for experienced programmers but shouldn't it work?
Thanks for your help.
Code:
Private Sub Orçamentar_Click()
Dim db As DAO.Database, rst As DAO.Recordset
Dim i As Integer, StartDate As Date, EndDate As Date, EmDate As Date, VenDate As Date, nRegistos As Integer
Dim Seg As String, Doc As String, nDoc As String, Val As Currency, Sit As String, Per As String, nPer As Integer
' Point to this database
Set db = CurrentDb
' Open a recordset on the table
Set rst = db.OpenRecordset("Fidelidade Mundial", dbOpenDynaset, dbAppendOnly)
'Ask for input How many records do you want to create
nRegistos = InputBox("Quantos registos quer criar", "My Inputbox")
'Grab the data off the form
Seg = Me.Seguro
Doc = Me.Documento
nDoc = ""
StartDate = Me.Data_Início
EndDate = Me.Data_Fim
EmDate = Me.Data_de_Emissão
VenDate = Me.Data_Vencimento
Val = Me.Valor_a_Pagar
Sit = "Orçamentado"
Per = Me.Periodicidade
If Per = "Mensal" Then nPer = 1
If Per = "Bimensal" Then nPer = 2
If Per = "Trimestral" Then nPer = 3
If Per = "Semestral" Then nPer = 6
If Per = "Anual" Then nPer = 12
'Loop to add records
For i = 1 To nRegistos
'Add a new record
rst.AddNew
'Populate the fields of the new record
rst![Seguro] = Seg
rst![Documento] = Doc
rst![Data Início] = DateAdd(m, nPer, StartDate)
rst![Data Fim] = DateAdd(Dateinterval.Month, nPer, EndDate)
rst![Data de Emissão] = DateAdd(Dateinterval.Month, nPer, EmDate)
rst![Data Vencimento] = DateAdd(Dateinterval.Month, nPer, VenDate)
rst![Situação] = Sit
rst![Periodicidade] = Per
rst.Update
rst.Close
nPer = nPer * i
Next
Set rst = Nothing
Set db = Nothing
End Sub