SheilaAlighieri
Technical User
Hi! Can anyone help me to recode this Access 2000 VBA code so it is compatible with Access 97? I really don't know how to.
Maybe one of you can help me with another small problem. This code selects all records in my table budget and then compares it to the data entered in a form (to which this code is attached). When the data is similar, it doesn't copy the data to the table. When it's unique, the data is copied. I only have some difficulties comparing the fields "BudgetDate" and "InvoiceDte", cause the Budgetdate is the Invoicedate + one year. I coded it as follows in rst.AddNew: rst!BudgetDate = DateAdd("yyyy", 1, InvoiceDte). But I don't know how to code this in rst.open.
Private Sub Button__Add__Click()
On Error GoTo Err_Button__Add__Click
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenKeyset
rst.LockType = adLockPessimistic
If (MsgBox("The system will now copy this invoice to the budget of next year.", vbInformation + vbOKCancel, "Confirm"
= vbOK) Then
rst.Open "SELECT * " _
& "FROM Budget " _
& "WHERE (AccountCode = " & AccountName & "
" _
& "AND (PlanRegion = '" & PlanRegion & "') " _
& "AND (Country = '" & Country & "')" _
& "AND (Place = '" & Place & "') " _
& "AND (Channel = '" & Channel & "')" _
& "AND (CodeCategory = " & CategoryName & "
" _
& "AND (CodeSort = " & SortName & "
" _
& "AND (Description = '" & Description & "');"
If rst.EOF Then
rst.AddNew
rst!AccountCode = AccountName
rst!BudgetDate = DateAdd("yyyy", 1, InvoiceDte)
rst!Budget = Amount / Rate
rst!Planned = Amount / Rate
rst!PlanRegion = PlanRegion
rst!Country = Country
rst!Place = Place
rst!Channel = Channel
rst!CodeCategory = CategoryName
rst!CodeSort = SortName
rst!Description = Description
rst.Update
DoCmd.GoToRecord , , acNext
DoCmd.Beep
Call MsgBox("Invoice copied.", vbInformation, "Success"
Else
DoCmd.Beep
MsgBox "This invoice is already in next year's budget.", vbCritical, "Error"
End If
rst.Close
Set rst = Nothing
End If
Exit_Err_Button__Add__Click:
Exit Sub
Err_Button__Add__Click:
DoCmd.Beep
MsgBox "You haven't entered all required data", vbCritical, "Error"
Resume Exit_Err_Button__Add__Click
End Sub
Regards,
Sheila
Maybe one of you can help me with another small problem. This code selects all records in my table budget and then compares it to the data entered in a form (to which this code is attached). When the data is similar, it doesn't copy the data to the table. When it's unique, the data is copied. I only have some difficulties comparing the fields "BudgetDate" and "InvoiceDte", cause the Budgetdate is the Invoicedate + one year. I coded it as follows in rst.AddNew: rst!BudgetDate = DateAdd("yyyy", 1, InvoiceDte). But I don't know how to code this in rst.open.
Private Sub Button__Add__Click()
On Error GoTo Err_Button__Add__Click
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenKeyset
rst.LockType = adLockPessimistic
If (MsgBox("The system will now copy this invoice to the budget of next year.", vbInformation + vbOKCancel, "Confirm"
rst.Open "SELECT * " _
& "FROM Budget " _
& "WHERE (AccountCode = " & AccountName & "
& "AND (PlanRegion = '" & PlanRegion & "') " _
& "AND (Country = '" & Country & "')" _
& "AND (Place = '" & Place & "') " _
& "AND (Channel = '" & Channel & "')" _
& "AND (CodeCategory = " & CategoryName & "
& "AND (CodeSort = " & SortName & "
& "AND (Description = '" & Description & "');"
If rst.EOF Then
rst.AddNew
rst!AccountCode = AccountName
rst!BudgetDate = DateAdd("yyyy", 1, InvoiceDte)
rst!Budget = Amount / Rate
rst!Planned = Amount / Rate
rst!PlanRegion = PlanRegion
rst!Country = Country
rst!Place = Place
rst!Channel = Channel
rst!CodeCategory = CategoryName
rst!CodeSort = SortName
rst!Description = Description
rst.Update
DoCmd.GoToRecord , , acNext
DoCmd.Beep
Call MsgBox("Invoice copied.", vbInformation, "Success"
Else
DoCmd.Beep
MsgBox "This invoice is already in next year's budget.", vbCritical, "Error"
End If
rst.Close
Set rst = Nothing
End If
Exit_Err_Button__Add__Click:
Exit Sub
Err_Button__Add__Click:
DoCmd.Beep
MsgBox "You haven't entered all required data", vbCritical, "Error"
Resume Exit_Err_Button__Add__Click
End Sub
Regards,
Sheila