PowerPoint/MS 获得 VBA 帮助
PowerPoint/MS Access VBA assistance
我正在尝试通过将 MS Access 数据库链接到 PowerPoint 来自动执行报告编写过程。我不知道如何使代码将查询输出到文本框中。代码 运行 没问题,直到带有“******”的那一行。有谁知道如何使 label1.value 等于查询输出?谢谢!
Dim Connect As String, Source As String
Dim Connection As ADODB.Connection
Dim Recordset1 As ADODB.Recordset
'Database path info
Dim FD As FileDialog
Dim vrtSelectedItem As Variant
Dim fileName As String
Set FD = Application.FileDialog(msoFileDialogFilePicker)
With FD
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
MsgBox "The path is: " & vrtSelectedItem
'Open the connection
Set Connection = New ADODB.Connection
Connect = "Provider=Microsoft.ACE.OLEDB.12.0;"
Connect = Connect & "Data Source=" & vrtSelectedItem & ";"
Connection.Open ConnectionString:=Connect
'Set RecordSet
Set Recordset1 = New ADODB.Recordset
With Recordset1
Source = "SELECT [xxx] FROM [yyy] WHERE [zzz] = '12345'"
.Open Source:=Source, ActiveConnection:=Connection
********
***Label1.Value = Recordset1***
********
End With
Next vrtSelectedItem
End If
End With
End Sub
Do
Label1.Value = Label1.Value & vbCrLf & Recordset1.Fields("[YOUR FIELD]").Value
Recordset1.MoveNext
Loop Until Recordset1.EOF
此代码将显示您查询中的所有记录([YOUR FIELD] 字段)。
But you need to add Recordset1.RecordCount to avoid the error.
If Recordset1.RecordCount > 0 Then
Do
Label1.Value = Label1.Value & vbCrLf & Recordset1.Fields("[YOUR FIELD]").Value
Recordset1.MoveNext
Loop Until Recordset1.EOF
End If
我正在尝试通过将 MS Access 数据库链接到 PowerPoint 来自动执行报告编写过程。我不知道如何使代码将查询输出到文本框中。代码 运行 没问题,直到带有“******”的那一行。有谁知道如何使 label1.value 等于查询输出?谢谢!
Dim Connect As String, Source As String
Dim Connection As ADODB.Connection
Dim Recordset1 As ADODB.Recordset
'Database path info
Dim FD As FileDialog
Dim vrtSelectedItem As Variant
Dim fileName As String
Set FD = Application.FileDialog(msoFileDialogFilePicker)
With FD
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
MsgBox "The path is: " & vrtSelectedItem
'Open the connection
Set Connection = New ADODB.Connection
Connect = "Provider=Microsoft.ACE.OLEDB.12.0;"
Connect = Connect & "Data Source=" & vrtSelectedItem & ";"
Connection.Open ConnectionString:=Connect
'Set RecordSet
Set Recordset1 = New ADODB.Recordset
With Recordset1
Source = "SELECT [xxx] FROM [yyy] WHERE [zzz] = '12345'"
.Open Source:=Source, ActiveConnection:=Connection
********
***Label1.Value = Recordset1***
********
End With
Next vrtSelectedItem
End If
End With
End Sub
Do
Label1.Value = Label1.Value & vbCrLf & Recordset1.Fields("[YOUR FIELD]").Value
Recordset1.MoveNext
Loop Until Recordset1.EOF
此代码将显示您查询中的所有记录([YOUR FIELD] 字段)。
But you need to add Recordset1.RecordCount to avoid the error.
If Recordset1.RecordCount > 0 Then
Do
Label1.Value = Label1.Value & vbCrLf & Recordset1.Fields("[YOUR FIELD]").Value
Recordset1.MoveNext
Loop Until Recordset1.EOF
End If