J
james.eacret
Greetings all,
I am using Office 2003 and Windows XP.
I am having various troubles with VBA after upgrading from 97 to 2000.
Recently this forum has proven very helpful. Forgive me, but I must
rely on people's expertise one more time.
The problem is when a report is run it was erroring out. It failed to
recognize OpenQueryDef. I changed this to what Access 2000 recognizes
(QueryDef), but it seems to have caused more errors. Below is the
original code (97) and what I have altered to get it to run...without
success yet.
The 97 Version:
Code:
Private Function HistAvg()
Dim ThisDB As Database, qdfHistAvg As QueryDef, recHistAvg As Recordset
Dim CodeVar As String, datevar As Variant, WellVar As String, strSQL As
String
Set ThisDB = CurrentDb()
On Error GoTo HistAvgEhandler
'Assign the variables from the current controls on the report
datevar = Reports![rptAnnual].[EndDate]
CodeVar = Reports![rptAnnual].[ParamCode]
WellVar = Reports![rptAnnual].[WellNo]
'Assign the query definition - the query definition is
created/destroyed by code in Report OnOpen/OnClose methods
Set qdfHistAvg = ThisDB.OpenQueryDef("ztqselAnnualRep")
strSQL = "SELECT DISTINCTROW
Avg(TrueValue([Anavalue],[ProjectAnavalue])) AS Anaval "
strSQL = strSQL & "FROM [tblAnavalue] "
strSQL = strSQL & "WHERE ((tblAnavalue.WDNRWellNo = '" & WellVar & "')
AND (tblAnavalue.DateCollected<=#" & datevar & "#) AND
(tblAnavalue.WDNRParameterCode ='" & CodeVar & "') AND
((TrueQual([DNRQualifier],[ProjectQualifier]))='=' Or
(TrueQual([DNRQualifier],[ProjectQualifier]))='J'));"
qdfHistAvg.SQL = strSQL
Set recHistAvg = ThisDB.OpenRecordset("ztqselAnnualRep")
HistAvg = recHistAvg.Anaval
'Close the query definition
qdfHistAvg.Close
Exit Function
HistAvgEhandler:
If Err = 3011 Then
Set qdfHistAvg = ThisDB.CreateQueryDef("ztqselAnnualRep")
Resume Next
Else
MsgBox Error & " Error No. " & Err
Exit Function
End If
End Function
I have altered it to this:
Code:
Private Function HistAvg()
Dim ThisDB As Database, qdfHistAvg As DAO.QueryDef, recHistAvg As
DAO.Recordset
Dim CodeVar As String, datevar As Variant, WellVar As String, strSQL As
String
Set ThisDB = CurrentDb
On Error GoTo HistAvgEhandler
'Assign the variables from the current controls on the report
datevar = Reports![rptAnnual].[EndDate]
CodeVar = Reports![rptAnnual].[ParamCode]
WellVar = Reports![rptAnnual].[WellNo]
'Assign the query definition - the query definition is
created/destroyed by code in Report OnOpen/OnClose methods
Set qdfHistAvg = ThisDB.QueryDefs("ztqselAnnualRep")
strSQL = "SELECT DISTINCTROW
Avg(TrueValue([Anavalue],[ProjectAnavalue])) AS Anaval "
strSQL = strSQL & "FROM [tblAnavalue] "
strSQL = strSQL & "WHERE ((tblAnavalue.WDNRWellNo = '" & WellVar & "')
AND (tblAnavalue.DateCollected<=#" & datevar & "#) AND
(tblAnavalue.WDNRParameterCode ='" & CodeVar & "') AND
((TrueQual([DNRQualifier],[ProjectQualifier]))='=' Or
(TrueQual([DNRQualifier],[ProjectQualifier]))='J'));"
qdfHistAvg.SQL = strSQL
Set recHistAvg = ThisDB.OpenRecordset("ztqselAnnualRep")
HistAvg = recHistAvg.Anaval
'Close the query definition
qdfHistAvg.Close
Exit Function
The current problem is on the line
Code:
HistAvg = recHistAvg.AnavalStating "Method or Data not found"
Having little experience updating code, I was hoping for some help, or
a point in the right direction. Thanks!
I am using Office 2003 and Windows XP.
I am having various troubles with VBA after upgrading from 97 to 2000.
Recently this forum has proven very helpful. Forgive me, but I must
rely on people's expertise one more time.
The problem is when a report is run it was erroring out. It failed to
recognize OpenQueryDef. I changed this to what Access 2000 recognizes
(QueryDef), but it seems to have caused more errors. Below is the
original code (97) and what I have altered to get it to run...without
success yet.
The 97 Version:
Code:
Private Function HistAvg()
Dim ThisDB As Database, qdfHistAvg As QueryDef, recHistAvg As Recordset
Dim CodeVar As String, datevar As Variant, WellVar As String, strSQL As
String
Set ThisDB = CurrentDb()
On Error GoTo HistAvgEhandler
'Assign the variables from the current controls on the report
datevar = Reports![rptAnnual].[EndDate]
CodeVar = Reports![rptAnnual].[ParamCode]
WellVar = Reports![rptAnnual].[WellNo]
'Assign the query definition - the query definition is
created/destroyed by code in Report OnOpen/OnClose methods
Set qdfHistAvg = ThisDB.OpenQueryDef("ztqselAnnualRep")
strSQL = "SELECT DISTINCTROW
Avg(TrueValue([Anavalue],[ProjectAnavalue])) AS Anaval "
strSQL = strSQL & "FROM [tblAnavalue] "
strSQL = strSQL & "WHERE ((tblAnavalue.WDNRWellNo = '" & WellVar & "')
AND (tblAnavalue.DateCollected<=#" & datevar & "#) AND
(tblAnavalue.WDNRParameterCode ='" & CodeVar & "') AND
((TrueQual([DNRQualifier],[ProjectQualifier]))='=' Or
(TrueQual([DNRQualifier],[ProjectQualifier]))='J'));"
qdfHistAvg.SQL = strSQL
Set recHistAvg = ThisDB.OpenRecordset("ztqselAnnualRep")
HistAvg = recHistAvg.Anaval
'Close the query definition
qdfHistAvg.Close
Exit Function
HistAvgEhandler:
If Err = 3011 Then
Set qdfHistAvg = ThisDB.CreateQueryDef("ztqselAnnualRep")
Resume Next
Else
MsgBox Error & " Error No. " & Err
Exit Function
End If
End Function
I have altered it to this:
Code:
Private Function HistAvg()
Dim ThisDB As Database, qdfHistAvg As DAO.QueryDef, recHistAvg As
DAO.Recordset
Dim CodeVar As String, datevar As Variant, WellVar As String, strSQL As
String
Set ThisDB = CurrentDb
On Error GoTo HistAvgEhandler
'Assign the variables from the current controls on the report
datevar = Reports![rptAnnual].[EndDate]
CodeVar = Reports![rptAnnual].[ParamCode]
WellVar = Reports![rptAnnual].[WellNo]
'Assign the query definition - the query definition is
created/destroyed by code in Report OnOpen/OnClose methods
Set qdfHistAvg = ThisDB.QueryDefs("ztqselAnnualRep")
strSQL = "SELECT DISTINCTROW
Avg(TrueValue([Anavalue],[ProjectAnavalue])) AS Anaval "
strSQL = strSQL & "FROM [tblAnavalue] "
strSQL = strSQL & "WHERE ((tblAnavalue.WDNRWellNo = '" & WellVar & "')
AND (tblAnavalue.DateCollected<=#" & datevar & "#) AND
(tblAnavalue.WDNRParameterCode ='" & CodeVar & "') AND
((TrueQual([DNRQualifier],[ProjectQualifier]))='=' Or
(TrueQual([DNRQualifier],[ProjectQualifier]))='J'));"
qdfHistAvg.SQL = strSQL
Set recHistAvg = ThisDB.OpenRecordset("ztqselAnnualRep")
HistAvg = recHistAvg.Anaval
'Close the query definition
qdfHistAvg.Close
Exit Function
The current problem is on the line
Code:
HistAvg = recHistAvg.AnavalStating "Method or Data not found"
Having little experience updating code, I was hoping for some help, or
a point in the right direction. Thanks!