【vb精品源码栏目提醒】:网学会员为需要vb精品源码的朋友们搜集整理了【精品】ACCESS 数据输入查询计算连接 - 其它资料相关资料,希望对各位网友有所帮助!
第4章 数据输入、查询、计算、连接:通过英特网的 ACCESS 联接在 ACCESS 中使用 ADO:Private Sub ABC_ClickDim cn As New ADODB.ConnectionDim rs As New ADODB.Recordsetcn.OPEN quotDSNalwinUIDPWDquotrs.OPEN quotSelect from tbTABLEquot cn adOpenDynamic adLockReadOnly’rs.ABC App.Path amp quottestdata.datquot adPersistADTGrs.Closecn.CloseMsgBox quotOPERATION OKquotEnd SubPrivate Sub OPEN_ClickDim strConnect As StringstrConnect quotProviderMSPersistquotDim rs As New ADODB.Recordsetrs.OPEN quothttp://远程服务器的 IP/test/testdata.datquot strConnectDo While Not rs.EOFDebug.Print rsquotUSERIDquot.valuers.MoveNextLoopEnd Sub将用户输入的身份证号 15 位数据转化为 18 位。
Function IDCode15to18sCode15 As String As String 功能:将 15 的身份证号升为 18 位根据 GB 11643-1999 参数:原来的号码 返回:升位后的 18 位号码 Dim i As Integer Dim num As Integer Dim code As String num 0 IDCode15to18 LeftsCode15 6 quot19quot RightsCode15 9 计算校验位 For i 18 To 2 Step -1 num num 2 i - 1 Mod 11 MidIDCode15to18 19 - i 1 Next i num num Mod 11 Select Case num Case 0 code quot1quot Case 1 code quot0quot Case 2 code quotXquot Case Else code TrimStr12 - num End Select IDCode15to18 IDCode15to18 codeEnd Function据身份证号自动输入出生日期Dim Length As IntegerLength LenMe.身份证号If Not IsNullLength Then If Length 15 Then Me.性别 IIfValMidMe.身份证号 15 1 / 2 IntValMidMe.身份证号 15 1 / 2 quot女quotquot男quot Me.出生日期 quot19quot amp Mid身份证号 7 2 amp quot-quot amp Mid身份证号 9 2 amp quot-quot amp Mid身份证号 11 2ElseIf Length 18 Then Me.性别 IIfValMidMe.身份证号 17 1 / 2 IntValMidMe.身份证号 17 1 / 2 quot女quot quot男quot Me.出生日期 Mid身份证号 7 4 amp quot-quot amp Mid身份证号 11 2 amp quot-quot amp Mid身份证号 13 2 Else MsgBox quot身份证号错误!quot End IfEnd If两行代码打开另一数据库Private Sub 命令 4_ClickOn Error GoTo Err_命令 4_ClickDim strDb As StringstrDb quotC:db1.mdbquotSendKeys quotF11FOquot amp strDb amp quotenterquotExit_命令 4_Click: Exit SubErr_命令 4_Click: MsgBox Err.Description Resume Exit_命令 4_ClickEnd Sub实现打开外部数据库中的报表。
Private Declare Function apiSetForegroundWindow Lib quotuser32quot _ Alias quotSetForegroundWindowquot _ ByVal hwnd As Long _ As LongPrivate Declare Function apiShowWindow Lib quotuser32quot _ Alias quotShowWindowquot _ ByVal hwnd As Long _ ByVal nCmdShow As Long _ As LongPrivate Const SW_MAXIMIZE 3Private Const SW_NORMAL 1Function fOpenRemoteReportstrMDB As String strReport As String _ Optional intView As Variant _ As Boolean strMDB: 外部数据库名称含路径 strReport: 报表名称 intView: 报表的打开方式 Dim objAccess As Access.Application Dim lngRet As Long On Error GoTo fOpenRemoteReport_Err If IsMissingintView Then intView acViewPreview If LenDirstrMDB gt 0 Then Set objAccess New Access.Application With objAccess lngRet apiSetForegroundWindow.hWndAccessApp lngRet apiShowWindow.hWndAccessApp SW_NORMAL 第一次调用 ShowWindow 似乎不做任何事情 lngRet apiShowWindow.hWndAccessApp SW_NORMAL .OpenCurrentDatabase strMDB .DoCmd.OpenReport strReport intView Do While Len.CurrentDb.Name gt 0 DoEvents Loop End With End IffOpenRemoteReport_Exit: On Erro