bizio
2010-01-20 15:01:28 UTC
Salve a tutti di nuovo,
lavoro con Access 2007 e sto cercando di creare una combo che
racchiuda la lista dei miei reports e con un pulsante di comando mi
apri quello selezionato.
Ho trovato un metodo cercando su internet ma presenta un errore e non
capisco come risolverlo.
Questa è la procedura:
1. Creato una form con:
* una combo box chiamata lstReports , con etichetta
Reports ;
* una check box chiamata chkPreview , con etichetta
Preview ;
* un pulsante chiamato cmdOpenReport , con etichetta Open
Report .
2. Su evento OnClick del pulsante:
Private Sub cmdOpenReport_Click()
' Purpose: Opens the report selected in the list box.
On Error GoTo cmdOpenReport_ClickErr
If Not IsNull(Me.lstReports) Then
DoCmd.OpenReport Me.lstReports, IIf(Me.chkPreview.Value,
acViewPreview, acViewNormal)
End If
Exit Sub
cmdOpenReport_ClickErr:
Select Case Err.Number
Case 2501 ' Cancelled by user, or by NoData event.
MsgBox "Report cancelled, or no matching data.",
vbInformation, "Information"
Case Else
MsgBox "Error " & Err & ": " & Error$, vbInformation,
"cmdOpenReport_Click()"
End Select
Resume Next
End Sub
3. sulla proprietà origine riga della combo impostata a
EnumReports . Lasciato Origine Controllo a blank.
4. Creato a nuovo modulo con il seguente codice:
Function EnumReports(fld As Control, id As Variant, row As
Variant, col As Variant, code As Variant) As Variant
' Purpose: Supplies the name of all saved reports to a list
box.
' Usage: Set the list box's RowSourceType property to:?
EnumReports
' leaving its RowSource property blank.
' Notes: All arguments are provided to the function
automatically.
' Author: Allen Browne ***@allenbrowne.com
Feb.'97.
Dim db As Database, dox As Documents, i As Integer
Static sRptName(255) As String ' Array to store
report names.
Static iRptCount As Integer ' Number of
saved reports.
' Respond to the supplied value of "code".
Select Case code
Case acLBInitialize ' Called once
when form opens.
Set db = CurrentDb()
Set dox = db.Containers!Reports.Documents
iRptCount = dox.Count ' Remember
number of reports.
For i = 0 To iRptCount - 1
sRptName(i) = dox(i).Name ' Load report
names into array.
Next
EnumReports = True
Case acLBOpen
EnumReports = Timer ' Return a
unique identifier.
Case acLBGetRowCount ' Number of rows
EnumReports = iRptCount
Case acLBGetColumnCount ' 1 column
EnumReports = 1
Case acLBGetColumnWidth ' 2 inches
EnumReports = 2 * 1440
Case acLBGetValue ' The report
name from the array.
EnumReports = sRptName(row)
Case acLBEnd
Erase sRptName ' Deallocate
array.
iRptCount = 0
End Select
End Function
ma quando apro la maschera mi dà error di run-time '13' Tipo non
corrispondente
e mi evidenzia la linea di codice:
Set dox = db.Containers!Reports.Documents
e sulla combo non compare nulla.
Sapete spiegarmi il motivo?
O in alternativa conoscete un metodo simile che funzioni?
Grazie mille dei vostri suggerimenti
lavoro con Access 2007 e sto cercando di creare una combo che
racchiuda la lista dei miei reports e con un pulsante di comando mi
apri quello selezionato.
Ho trovato un metodo cercando su internet ma presenta un errore e non
capisco come risolverlo.
Questa è la procedura:
1. Creato una form con:
* una combo box chiamata lstReports , con etichetta
Reports ;
* una check box chiamata chkPreview , con etichetta
Preview ;
* un pulsante chiamato cmdOpenReport , con etichetta Open
Report .
2. Su evento OnClick del pulsante:
Private Sub cmdOpenReport_Click()
' Purpose: Opens the report selected in the list box.
On Error GoTo cmdOpenReport_ClickErr
If Not IsNull(Me.lstReports) Then
DoCmd.OpenReport Me.lstReports, IIf(Me.chkPreview.Value,
acViewPreview, acViewNormal)
End If
Exit Sub
cmdOpenReport_ClickErr:
Select Case Err.Number
Case 2501 ' Cancelled by user, or by NoData event.
MsgBox "Report cancelled, or no matching data.",
vbInformation, "Information"
Case Else
MsgBox "Error " & Err & ": " & Error$, vbInformation,
"cmdOpenReport_Click()"
End Select
Resume Next
End Sub
3. sulla proprietà origine riga della combo impostata a
EnumReports . Lasciato Origine Controllo a blank.
4. Creato a nuovo modulo con il seguente codice:
Function EnumReports(fld As Control, id As Variant, row As
Variant, col As Variant, code As Variant) As Variant
' Purpose: Supplies the name of all saved reports to a list
box.
' Usage: Set the list box's RowSourceType property to:?
EnumReports
' leaving its RowSource property blank.
' Notes: All arguments are provided to the function
automatically.
' Author: Allen Browne ***@allenbrowne.com
Feb.'97.
Dim db As Database, dox As Documents, i As Integer
Static sRptName(255) As String ' Array to store
report names.
Static iRptCount As Integer ' Number of
saved reports.
' Respond to the supplied value of "code".
Select Case code
Case acLBInitialize ' Called once
when form opens.
Set db = CurrentDb()
Set dox = db.Containers!Reports.Documents
iRptCount = dox.Count ' Remember
number of reports.
For i = 0 To iRptCount - 1
sRptName(i) = dox(i).Name ' Load report
names into array.
Next
EnumReports = True
Case acLBOpen
EnumReports = Timer ' Return a
unique identifier.
Case acLBGetRowCount ' Number of rows
EnumReports = iRptCount
Case acLBGetColumnCount ' 1 column
EnumReports = 1
Case acLBGetColumnWidth ' 2 inches
EnumReports = 2 * 1440
Case acLBGetValue ' The report
name from the array.
EnumReports = sRptName(row)
Case acLBEnd
Erase sRptName ' Deallocate
array.
iRptCount = 0
End Select
End Function
ma quando apro la maschera mi dà error di run-time '13' Tipo non
corrispondente
e mi evidenzia la linea di codice:
Set dox = db.Containers!Reports.Documents
e sulla combo non compare nulla.
Sapete spiegarmi il motivo?
O in alternativa conoscete un metodo simile che funzioni?
Grazie mille dei vostri suggerimenti