R
RCR
Hi There
I am trying to reset the page number and page count for each group in my
database report. I downloaded Article ID 841779, and although I am not too
great at Visual Basic, I managed to use the example in the Northwind
database, which worked perfectly.
However, when I try and adapt the code to run on my database I get the
following error message 'The expression On Open you entered as event property
setting produced following error : User-defined type not defined'. The only
alterations I made to the code was replace [Country] with my group [ATA]. The
table that I created to store group names and pages is same as example. Also,
as I don't have much code in my database, I was unsure where to apend the
definition of variables for Database & Recordset (see copy of code)
Option Compare Database
Dim DB As Database
Dim GrpPages As Recordset
Function GetGrpPages()
'Find the group name.
GrpPages.Seek "=", Me![ATA]
If Not GrpPages.NoMatch Then
GetGrpPages = GrpPages![Page Number]
End If
End Function
Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
'Set page number to 1 when new group starts.
Page = 1
End Sub
Private Sub PageFooter3_Format(Cancel As Integer, FormatCount As Integer)
'Find the group.
GrpPages.Seek "=", Me![ATA]
If Not GrpPages.NoMatch Then
'The group is already there.
If GrpPages![Page Number] < Me.Page Then
GrpPages.Edit
GrpPages![Page Number] = Me.Page
GrpPages.Update
End If
Else
'This is the first page of the group. Therefore, add it.
GrpPages.AddNew
GrpPages![ATA] = Me![ATA]
GrpPages![Page Number] = Me.Page
GrpPages.Update
End If
End Sub
Private Sub Report_Open(Cancel As Integer)
Set DB = DBEngine.Workspaces(0).Databases(0)
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete * From [Category Group Pages];"
DoCmd.SetWarnings True
Set GrpPages = DB.OpenRecordset("Category Group Pages", DB_OPEN_TABLE)
GrpPages.Index = "PrimaryKey"
End Sub
If anyone could help in sorting this problem, I would be most grateful
I am trying to reset the page number and page count for each group in my
database report. I downloaded Article ID 841779, and although I am not too
great at Visual Basic, I managed to use the example in the Northwind
database, which worked perfectly.
However, when I try and adapt the code to run on my database I get the
following error message 'The expression On Open you entered as event property
setting produced following error : User-defined type not defined'. The only
alterations I made to the code was replace [Country] with my group [ATA]. The
table that I created to store group names and pages is same as example. Also,
as I don't have much code in my database, I was unsure where to apend the
definition of variables for Database & Recordset (see copy of code)
Option Compare Database
Dim DB As Database
Dim GrpPages As Recordset
Function GetGrpPages()
'Find the group name.
GrpPages.Seek "=", Me![ATA]
If Not GrpPages.NoMatch Then
GetGrpPages = GrpPages![Page Number]
End If
End Function
Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
'Set page number to 1 when new group starts.
Page = 1
End Sub
Private Sub PageFooter3_Format(Cancel As Integer, FormatCount As Integer)
'Find the group.
GrpPages.Seek "=", Me![ATA]
If Not GrpPages.NoMatch Then
'The group is already there.
If GrpPages![Page Number] < Me.Page Then
GrpPages.Edit
GrpPages![Page Number] = Me.Page
GrpPages.Update
End If
Else
'This is the first page of the group. Therefore, add it.
GrpPages.AddNew
GrpPages![ATA] = Me![ATA]
GrpPages![Page Number] = Me.Page
GrpPages.Update
End If
End Sub
Private Sub Report_Open(Cancel As Integer)
Set DB = DBEngine.Workspaces(0).Databases(0)
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete * From [Category Group Pages];"
DoCmd.SetWarnings True
Set GrpPages = DB.OpenRecordset("Category Group Pages", DB_OPEN_TABLE)
GrpPages.Index = "PrimaryKey"
End Sub
If anyone could help in sorting this problem, I would be most grateful