用data控件与excel连结

liu_swallow 2003-06-29 01:49:22
在程序中不能重新定义data1的连结属性
data1.databasename=commondialog1.filename
tempstring=commondialog1.filename
‘ 处理tempstring为文件名(文件名即为数据表名)如:book1.xls中有数据表book1
data1.recordsource=tempstring
data1.refresh出错,“外部数据库不支持此方法
data1.updatecontrols
...全文
104 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gpo2002 2003-06-29
  • 打赏
  • 举报
回复
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text2
DataField = "F3"
DataSource = "Data2"
Height = 375
Left = 360
TabIndex = 4
Text = "Text2"
Top = 1560
Width = 975
End
Begin VB.Data Data2
Caption = "Data2"
Connect = "Excel 8.0;"
DatabaseName = "C:\Book1.xls"
DefaultCursorType= 0 '缺省游标
DefaultType = 2 '使用 ODBC
Exclusive = 0 'False
Height = 345
Left = 480
Options = 0
ReadOnly = 0 'False
RecordsetType = 0 'Table
RecordSource = "Sheet1$"
Top = 2400
Width = 1740
End
Begin VB.Data Data1
Caption = "Data1"
Connect = "Excel 8.0;"
DatabaseName = ""
DefaultCursorType= 0 '缺省游标
DefaultType = 2 '使用 ODBC
Exclusive = 0 'False
Height = 525
Left = 2640
Options = 0
ReadOnly = 0 'False
RecordsetType = 0 'Table
RecordSource = ""
Top = 240
Width = 1620
End
Begin VB.CommandButton Command3
Caption = "Command3"
Height = 495
Left = 1920
TabIndex = 3
Top = 1320
Width = 1215
End
Begin VB.TextBox Text1
DataSource = "Data1"
Height = 495
Left = 240
TabIndex = 2
Text = "Text1"
Top = 480
Width = 1335
End
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 495
Left = 3120
TabIndex = 1
Top = 2160
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 1800
TabIndex = 0
Top = 1320
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command2_Click()
Data1.Refresh
Data1.UpdateControls
End Sub

Private Sub Command3_Click()

Data1.DatabaseName = "C:\book1.xls"
Data1.RecordSource = "Sheet1$"

Data1.Refresh

Text1.DataField = "F3"
End Sub

liu_swallow 2003-06-29
  • 打赏
  • 举报
回复
有人能讲讲吗?
liu_swallow 2003-06-29
  • 打赏
  • 举报
回复
这个参数我已经设过了,(我是不能在程序中俢改轋结属性)
gpo2002 2003-06-29
  • 打赏
  • 举报
回复
data1.Connect = Excel 8.0
liu_swallow 2003-06-29
  • 打赏
  • 举报
回复
up

2,462

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧