外部から Access へアクセスする


  Access.Application




Excel や IE にも同様のインターフェイスがありますが、いろいろと便利なものがあります。基本的に、Access の VB 内でApplication. で出現するプロパティ・メソツド・コレクションが扱えます。

以下は、Visual Basic 6.0 のコードです

  

Dim ac

Private Sub Command1_Click()
   
    Set ac = CreateObject("Access.Application")
    
    ac.OpenCurrentDatabase ("C:\MDB\db1.mdb")
    
    With ac.CurrentDb
        
        For i = 0 To .TableDefs.Count - 1
    
            MsgBox .TableDefs(i).Connect & "/" & _
                    .TableDefs(i).Name & "/" & _
                    .TableDefs(i).SourceTableName
            
        Next
    
    End With

End Sub

Private Sub Command2_Click()

    ac.CloseCurrentDatabase
    Set ac = Nothing

End Sub
  

TableDefs コレクションと、TableDef オブジェクトは DAO です

  リンク先変更




C:\MDB\db1.mdb は、Access 2000 で、C:\MDB\link.MDB と C:\MDB\link2.MDB という Access 97 の MDB があります。Access 97 の中はどちらも同じで、TEST_TABLE という表があります

Access 2000 から、その C:\MDB\link.MDB 内の TEST_TABLE へのリンクを作成して、MyTABLE という名前で登録します。そして、以下のコードを実行します

  

Dim ac, newDef

Private Sub Command1_Click()

    Set ac = CreateObject("Access.Application")
   
    ac.OpenCurrentDatabase ("C:\MDB\db1.mdb")
    ac.CurrentDb.TableDefs.Delete ("MyTABLE")
    
    Set newDef = ac.CurrentDb.CreateTableDef("TEST")
    
    newDef.Connect = ";DATABASE=C:\MDB\link2.MDB"
    newDef.SourceTableName = "TEST_TABLE"
    newDef.Name = "MyTABLE"
    ac.CurrentDb.TableDefs.Append (newDef)

    ac.CloseCurrentDatabase
    Set ac = Nothing

End Sub
  

  フォームのプロパティ

フォームは、Open しないとプロパティを取得できないので、デザインビューで Open してから読み出して、処理が済んだらClose します(起動時の設定で、データベースウィンドウを表示するようにして下さい)

  

Const acDesign = 1
Const acForm = 2

Set ac = CreateObject("Access.Application")

ac.OpenCurrentDatabase( document.all("TargetMDB").value )

For i = 0 To ac.CurrentProject.AllForms.Count - 1

	frmName = ac.CurrentProject.AllForms(i).Name

	If Not ac.CurrentProject.AllForms(i).IsLoaded Then
		ac.DoCmd.OpenForm frmName, acDesign
	End If

	Set Prop = ac.Forms(frmName).Properties("Modal")

Prop.Value がプロパティ値

	If ac.CurrentProject.AllForms(i).IsLoaded Then
		ac.DoCmd.Close acForm, frmName
	End If

Next

ac.CloseCurrentDatabase
  




yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[access]
claudebot
24/04/19 05:13:45
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube