利用拆分后的后端数据库保存不同年份的数据

利用拆分后的后端数据库保存不同年份的数据,第1张

利用拆分后的后端数据库保存不同年份的数据,第2张

对于初学者
目的:如果一年的数据比较多,希望将数据库中的数据按年保存
知识点:1。数据库拆分
2。文件搜索技术。文件复制
4。链接表刷新
步骤。补充等。)并将表名的前两个字母改为common(如:Or_业务人员列表,Or_收货人列表等。).注意不要使用“MS”、“SW”、“US”等字母。
2。拆分数据库(如果前端名为:export business record.mdb,后端名为:export business record _ data origin . MDB
3。在启动窗体(如果名称为:Form 1)中创建一个文本框(如果名称为:year)
4。在Form 1的Open事件和当年的AfterUpdate事件中调用下面的“find files”过程。

子链接()

on Error GoTo LJ _ Error
Dim tab name As String
Dim tab 1 As TableDef
Dim my path As String

my path = application . current project . path
current db . table defs . refresh '刷新当前数据库中的表对象
如果currentdb.tabledefs (15)。connect = ";DATABASE = " & my path & " \ export business record _ data " & FORMs!表格1!年份&”。mdb”然后

出口接头

Else
用于CurrentDb中的每个Tab1。比如表定义

TABNAME = Tab1。Name
If Left(TABNAME,2) "MS "和Left(TABNAME,2) "SW "和Left(TABNAME,2) "Us" Then
If Left(TABNAME,2) = "Or" Then
Tab1。connect = ";DATABASE = " & my path & " \ export business record _ data origin . MDB "
else
tab 1 . connect = ";DATABASE = " & my path & " \ export business record _ data " & FORMs!表格1!年份&”。MDB"
end if
tab1。refreshlink
结束if

下一个Tab1
MsgBox表单!表格1!年&“年的基本数据库连接成功!”
End If
Exit _ LJ _ error:
Exit Sub

LJ_error:
MsgBox表单!表格1!年度&“年”的后端数据库文件不存在!
恢复Exit_LJ_error
End Sub

sub search file()
dimmy path as string
dimfs as variant
dim tabname as string
dim tab1 as tabledef

MyPath =应用程序。CurrentProject.Path

使用fs
进行set = application . file search
。lookin = mypath
。searchsubfolders = true
。filename = "导出业务记录_数据" & FORMs!表格1!年份&”。mdb "

如果。如果MsgBox ("none" & FORMs!表格1!year &“year,你想创建一个吗?”,vbYesNo) = vbYes Then
FORMs!1.形式!版本。form . record source = " "
file copy my path & " \ export business record _ data origin . MDB ",my path & " \ export business record _ data " & FORMs!表格1!年份&”。mdb"
Else
表单!表格1!Year = Year(Now())
MsgBox " none " & FORMs!表格1!年度&“年度数据库!”
exit Sub
End if
End if
End with
link
End Sub

4.在Form 1的Close事件中写入:
private subform _ Close()
dim tabname as string
dim tab 1 as tabledef
dimmy path as string。


my path = application . current project . path
current db . table defs . Refresh '刷新当前数据库中的表对象
if currentdb.tabledefs (15)。connect = ";DATABASE = " & my path & " \ export business record _ data " & Year(Now())& "。mdb”然后

对CurrentDb中的每个Tab1退出Sub
Else
。比如表定义

TABNAME = Tab1。Name
If Left(TABNAME,2) "MS "和Left(TABNAME,2) "SW "和Left(TABNAME,2) "Us" Then
If Left(TABNAME,2) = "Or" Then
Tab1。connect = ";DATABASE = " & my path & " \ export business record _ data origin . MDB "
else
tab 1 . connect = ";DATABASE = " & my path & " \ export business record _ data " & year(now())& "。MDB "
endif
tab 1 . refresh link
endif

next tab 1
End If
End Sub

请注意,Form 1是一个没有任何绑定控件的开关面板。如果有这样的控件,设置所有* * *源(如RcordSource、RowSource等。)= " "在更改链接表的connect属性和FileCopy之前,完成相关语句后再将其设置为原始值。

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » 利用拆分后的后端数据库保存不同年份的数据

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情