设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1103|回复: 2
打印 上一主题 下一主题

[其它] 做基本操作评分所用的几个函数

[复制链接]
跳转到指定楼层
1#
发表于 2007-4-15 03:52:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
想做一个ACCESS评分系统,总有些不尽人意,有更好的方法请指教

Function ISrecord(Mdb1, Mdb2, Table1) '不同数据库中表的记录比较
  Dim Acc As Access.Application
  Dim Sacc As Access.Application
  Dim Df, Sdf, i
On Error Resume Next
Set Acc = CreateObject("Access.Application")
Set Sacc = CreateObject("Access.Application")
Acc.OpenCurrentDatabase (Mdb1)
Sacc.OpenCurrentDatabase (Mdb2)
Set Df = Acc.CurrentDb.TableDefs(Table1).OpenRecordset
Set Sdf = Sacc.CurrentDb.TableDefs(Table1).OpenRecordset
  While Not Sdf.EOF
   For i = 0 To Sdf.Fields.Count - 1
    If Df(i) <> Sdf(i) Then GoTo AA
  Next
    Debug.Print
   Df.MoveNext
   Sdf.MoveNext
Wend
Df.Close
Sdf.Close
  ISrecord = True
GoTo End1
AA:
   ISrecord = False
End1:
Acc.CloseCurrentDatabase
Sacc.CloseCurrentDatabase
Set Acc = Nothing
Set Sacc = Nothing
End Function
Function Isp(tdf, kk, i) '字段属性出错处理
  On Error GoTo AA
  If IsNumeric(tdf.Fields(i).Properties(kk).Value) Then
    If tdf.Fields(i).Properties(kk).Value > 50 Then GoTo AA
  End If
Isp = True
Exit Function
AA:
  Isp = False
End Function
Function ISfield(Mdb1, Mdb2, Table1) '比较字段属性、类型、宽度、小数位、格式
   Dim Acc As Access.Application
  Dim Sacc As Access.Application
  Dim Df As TableDef, Sdf, i
  Dim kk
  Dim p
    kk = Array("Type", "Size", "DecimalPlaces", "Format")
  On Error Resume Next
Set Acc = CreateObject("Access.Application")
Set Sacc = CreateObject("Access.Application")
Acc.OpenCurrentDatabase (Mdb1)
Sacc.OpenCurrentDatabase (Mdb2)
Set ob1 = Acc.CurrentDb
Set ob2 = Sacc.CurrentDb
Set Df = ob1.TableDefs(Table1)
Set Sdf = ob2.TableDefs(Table1)
For i = 0 To Df.Fields.Count - 1
           For p = 0 To 3
             If Isp(Df, kk(p), i) = True Then
               If Isp(Sdf, kk(p), i) = False Then GoTo AA
               If Df.Fields(i).Properties(kk(p)).Value <> Sdf.Fields(i).Properties(kk(p)).Value Then
                GoTo AA
               End If
            End If
            
                'Debug.Print "表名:" & tdf.Name & _
                '           "; 字段名:" & fld.Name & _
                '          "; 属性名:" & fld.Properties(kk(p)).Name & _
                '         "; 属性值:" & fld.Properties(kk(p)).Value
            Next
        Next
ISfield = True
GoTo End1
AA:
   ISfield = False
End1:
Acc.CloseCurrentDatabase
Sacc.CloseCurrentDatabase
Set Acc = Nothing
Set Sacc = Nothing
End Function


Function IScheck(Mdb1, Mdb2, Table1, Field1) '比较规则、默认值、出错信息
   Dim Acc As Access.Application
  Dim Sacc As Access.Application
  Dim Df As TableDef, Sdf, i
  Dim kk
  Dim p
  i = Field1
  kk = Array("ValidationRule", "ValidationText", "DefauleValue")
On Error Resume Next
Set Acc = CreateObject("Access.Application")
Set Sacc = CreateObject("Access.Application")
Acc.OpenCurrentDatabase (Mdb1)
Sacc.OpenCurrentDatabase (Mdb2)
Set ob1 = Acc.CurrentDb
Set ob2 = Sacc.CurrentDb
Set Df = ob1.TableDefs(Table1)
Set Sdf = ob2.TableDefs(Table1)
  For p = 0 To 2
            If Isp(Df, kk(p), i) = True Then
               If Isp(Sdf, kk(p), i) = False Then GoTo AA
               If Df.Fields(i).Properties(kk(p)).Value <> Sdf.Fields(i).Properties(kk(p)).Value Then
                GoTo AA
              End If
            End If
                           
  Next
     
IScheck = True
GoTo End1
AA:
   IScheck = False
End1:
Acc.CloseCurrentDatabase
Sacc.CloseCurrentDatabase
Set Acc = Nothing
Set Sacc = Nothing
End Function


<FONT color=#800080>Function ISprimary(Mdb1, Table1, Field1, index1) 'index1 索引类型
  Dim td     As DAO.TableDef
  Dim db     As D
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2007-4-17 03:47:00 | 只看该作者
有实例的话更好。
3#
发表于 2007-4-17 03:49:00 | 只看该作者
不太懂
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-6-10 01:52 , Processed in 0.102115 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表