I'm executing the following procedure within Access mdb. The query that I'm trying to run works nolrmally when executed as Query.
Do anybody has any idea of reason of the error?.
Thanks a lot
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim Istruz As Variant
Dim MaxOfVersione As Integer
Istruz = "SELECT Max(ControlloVersioniBDG.Versione) AS MaxOfVersione" _
& " FROM ControlloVersioniBDG" _
& " GROUP BY ControlloVersioniBDG.BDGType, ControlloVersioniBDG.Anno" _
& " HAVING (ControlloVersioniBDG.BDGType=[Forms]![F_BDG]![TipoBDG])" _
& " AND (ControlloVersioniBDG.Anno=[Forms]![F_BDG]![DetControlloVersioni])"
DoCmd.RunSQL Istruz
[Forms]![NewControlloVersioniBDG]![Versione].DefaultValue = MaxOfVersione + 1
End Sub