Global It Leader!!



 
 

VB VB에서 MDB 생성하기 - 속성 자세히

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 5,278회 작성일 12-08-31 18:36

본문

' 아래는 MDB을 생성해 주는 소스입니다.
' 물론 인덱스 생성 소스도 있습니다.
' NewDb() 함수로 되어있는데, 함수의 인수값으로 아무것나
' 주면 이것이 MDB의 화일명이 됩니다.
' 아래는 하나의 MDB에 2개의 테이블을 생성한다.
' 이것을 비베에서 모듈로 불러와서
' Call NewDb("Test1.Mdb")
' 라고 화일명을 주면 Test1.mdb가 생성되므로
' Test1.mdb을 비주얼 데이타 관리자로
' 불러오면 확인할 수 있다.
' 그리고 필드 속성에 대해 약간의 설명을
' 달았으므로 참조하기 바람.

Option Explicit
Private Ws  As Workspace
Private Db  As Database
Private Td  As TableDef
Private Fld As Field
Private Idx As Index
Private Rel As Relation
Private Qd  As QueryDef

Public Sub NewDb(DbFilename as string)

    Dim IdxFldName as String
    Set Ws = DBEngine.Workspaces(0)

    ' 먼저 DbFilename 변수로 화일명을 생성한다.
    ' dbLangKorean은 랭귀지 정렬순서 값이다.
    ' 더 자세한 것은 도움말에서 CreateDatabase메소드를 참조.
    Set Db = Ws.CreateDatabase(DbFilename , dbLangKorean)


'    거래처 Is an Access table
    Set Td = Db.CreateTableDef("거래처") '거래처라는 테이블생성
        Set Fld = Td.CreateField()       '필드생성
            Fld.Name = "구분"            '필드명
            Fld.Type = 10              '필드타입(Text)-아래참조
            Fld.Size = 4                 '사이즈        
            Fld.Attributes = 2           '2는 가변필드
                                         '1은 고정필드
                       ' "Attributes 속성 상수" 도움말 참조
            Fld.Required = False            '필수
            Fld.AllowZeroLength = True      '0길이 허용
            Fld.DefaultValue = """"""       '기본값 ""을 적용
                                            '만약, 숫자일때는 0
                                            '을 대입하면 됨.
        Td.Fields.Append Fld                '* 필드 추가

                                    '필드Type   - 숫자값 -
                                    'Boolean    - 1
                                    'Byte       - 2
                                    'Integer    - 3
                                    'Long       - 4
                                    'Currency   - 5
                                    'Single     - 6
                                    'Double     - 7
                                    'Date/Time  - 8
                                    '           - 9번째는 없음.
                                    'Text       - 10
                                    'Binary     - 11
                                    'Memo       - 12


        Set Fld = Td.CreateField()      '2번째 필드 생성
            Fld.Name = "업체코드"
            Fld.Type = 10
            Fld.Size = 6
            Fld.Attributes = 2
            Fld.Required = False
            Fld.AllowZeroLength = True
            Fld.DefaultValue = """"""
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "상호"
            Fld.Type = 10
            Fld.Size = 30
            Fld.Attributes = 2
            Fld.Required = False
            Fld.AllowZeroLength = True
            Fld.DefaultValue = """"""
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "대표자명"
            Fld.Type = 10
            Fld.Size = 10
            Fld.Attributes = 2
            Fld.Required = False
            Fld.AllowZeroLength = True
            Fld.DefaultValue = """"""
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "주소"
            Fld.Type = 10
            Fld.Size = 70
            Fld.Attributes = 2
            Fld.Required = False
            Fld.AllowZeroLength = True
            Fld.DefaultValue = """"""
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "우편번호"
            Fld.Type = 10
            Fld.Size = 7
            Fld.Attributes = 2
            Fld.Required = False
            Fld.AllowZeroLength = True
            Fld.DefaultValue = """"""
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "전화번호"
            Fld.Type = 10
            Fld.Size = 20
            Fld.Attributes = 2
            Fld.Required = False
            Fld.AllowZeroLength = True
            Fld.DefaultValue = """"""
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "FAX"
            Fld.Type = 10
            Fld.Size = 20
            Fld.Attributes = 2
            Fld.Required = False
            Fld.AllowZeroLength = True
            Fld.DefaultValue = """"""
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "기타"
            Fld.Type = 10
            Fld.Size = 60
            Fld.Attributes = 2
            Fld.Required = False
            Fld.AllowZeroLength = True
            Fld.DefaultValue = """"""
        Td.Fields.Append Fld


'       인덱스 생성하기
        Set Idx = Td.CreateIndex("구분")    '인덱스명(구분)
            Idx.Fields = "+구분"            '필드명
            Idx.Primary = False
            Idx.Unique = False
            Idx.Required = False
        Td.Indexes.Append Idx
        Set Idx = Td.CreateIndex("구분업체") '두개의 필드로
                                             '인덱스할 때
            Idx.Fields = "+구분;+업체코드"  '+필드명;+필드명으
                                            '로 표기
            Idx.Primary = False
            Idx.Unique = False
            Idx.Required = False
        Td.Indexes.Append Idx
        Set Idx = Td.CreateIndex("대표자명")
            Idx.Fields = "+대표자명"
            Idx.Primary = False
            Idx.Unique = False
            Idx.Required = False
        Td.Indexes.Append Idx
        Set Idx = Td.CreateIndex("상호")
            Idx.Fields = "+상호"
            Idx.Primary = False
            Idx.Unique = False
            Idx.Required = False
        Td.Indexes.Append Idx
        Set Idx = Td.CreateIndex("업체코드")
            Idx.Fields = "+업체코드"
            Idx.Primary = True
            Idx.Unique = True
            Idx.Required = True
        Td.Indexes.Append Idx
    Db.TableDefs.Append Td        '하나의 테이블 추가


'    자재입고 Is an Access table
    Set Td = Db.CreateTableDef("자재입고")
        Set Fld = Td.CreateField()
            Fld.Name = "자재코드"
            Fld.Type = 10
            Fld.Size = 6
            Fld.Attributes = 2
            Fld.Required = False
            Fld.AllowZeroLength = True
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "자재명"
            Fld.Type = 10
            Fld.Size = 30
            Fld.Attributes = 2
            Fld.Required = False
            Fld.AllowZeroLength = True
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "규격"
            Fld.Type = 10
            Fld.Size = 20
            Fld.Attributes = 2
            Fld.Required = False
            Fld.AllowZeroLength = True
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "단위"
            Fld.Type = 10
            Fld.Size = 4
            Fld.Attributes = 2
            Fld.Required = False
            Fld.AllowZeroLength = True
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "단가"
            Fld.Type = 5
            Fld.Size = 8
            Fld.Attributes = 1
            Fld.Required = False
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "수량"
            Fld.Type = 5
            Fld.Size = 8
            Fld.Attributes = 1
            Fld.Required = False
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "금액"
            Fld.Type = 5
            Fld.Size = 8
            Fld.Attributes = 1
            Fld.Required = False
        Td.Fields.Append Fld
        Set Fld = Td.CreateField()
            Fld.Name = "변경일"
            Fld.Type = 8
            Fld.Size = 8
            Fld.Attributes = 1
            Fld.Required = False
        Td.Fields.Append Fld


'       '인덱스 생성
        Set Idx = Td.CreateIndex("자재코드")
            Idx.Fields = "+자재코드"
            Idx.Primary = False
            Idx.Unique = False
            Idx.Required = False
        Td.Indexes.Append Idx
    Db.TableDefs.Append Td


    Db.Close
    Set Qd = Nothing
    Set Rel = Nothing
    Set Idx = Nothing
    Set Fld = Nothing
    Set Td = Nothing
    Set Db = Nothing
    Set Ws = Nothing
End Sub

[이 게시물은 오원장님에 의해 2013-02-28 16:41:58 오피스팁에서 이동 됨]

댓글목록

등록된 댓글이 없습니다.

전체 95
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
35 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10036 07-15
34 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8110 07-14
33 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7421 07-14
32 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8897 07-13
31 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8962 07-13
30 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7567 07-08
29 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7251 07-08
28 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8597 07-08
27 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8090 07-08
26 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7887 07-08
25 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8249 07-08
24 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9306 07-05
23 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8799 07-04
22 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8872 07-02
21 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8091 07-01
20 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4865 10-29
19 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5319 08-31
18 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10433 08-31
열람중 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5279 08-31
16 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6574 08-31