비베 MS엑세스 연동
비주얼베이직고수님들!!! (내공팍팍!!) indyp (2006-10-26 19:56 작성)
질문자 평
감사합니다~!
님 시간이 많이 걸려서 다른분들이 접근하지 않나봅니다.
학생 같아서 답변해드릴게요
먼저 폼설명
각 컨포넌트 속성 이름부터 나갑니다.
텍스트 박스는 위서부터 아래로 보이는 값이 속성이름입니다.
다음 신규버튼은 단순히 필드를 지우는 역활 밖에 없고 속성이름은 ComNew
저장버튼은 ComSave이며 종료버튼은 ComExit
삭제는 ComDel, 찾기버튼은 ComFind 입니다.
그러면 폼은 끝났으니 소스로 ....
Option Explicit
Dim Wspace As Workspace
Dim DB As dao.Database
Dim RS As dao.Recordset
Dim PathDB As String
Dim iSQL As String
Private Sub ComDel_Click() '삭제
'찾기로 찾은 다음 삭제 가능합니다.
iSQL = "select * from MenberTbl " & _
"where MenberJumiNo='" & Trim(Text5.Text) & "' "
Set RS = DB.OpenRecordset(iSQL)
If RS.RecordCount > 0 Then
RS.Delete
masbox "삭제 되었습니다."
End If
RS.Close
End Sub
Private Sub ComFind_Click() '찾기
iSQL = "select * from MenberTbl " & _
"where MenberJumiNo='" & Trim(Text5.Text) & "' "
Set RS = DB.OpenRecordset(iSQL)
If RS.RecordCount > 0 Then
Text1.Text = RS!MenberName
Text2.Text = RS!MenberSex
Text3.Text = RS!MenberJumiNo
Text4.Text = RS!MenberTelno
Text5.Text = "" '찾기입력 필드
End If
RS.Close
End Sub
Private Sub ComNew_Click() '신규
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text1.SetFocus
End Sub
Private Sub ComExit_Click() '종료
Unload Me
End Sub
Private Sub ComSave_Click() '저장
If Text1.Text <> "" And Text2.Text <> "" And Text3.Text <> "" And Text4.Text <> "" Then
iSQL = "select * from MenberTbl "
Set RS = DB.OpenRecordset(iSQL)
RS.AddNew
RS!MenberName = Text1.Text
RS!MenberSex = Text2.Text
RS!MenberJumiNo = Text3.Text
RS!MenberTelno = Text4.Text
RS.Update
RS.Close
End If
Call ComNew_Click
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
PathDB = App.Path & "\고객DB.mdb"
Set Wspace = DBEngine.Workspaces(0)
If Dir(PathDB) = "" Then 'MDB파일 존재 여부를 검사하고 없으면 생성
Call CreateDB
End If
'DB OPEN
Set DB = OpenDatabase(PathDB)
End Sub
Public Function CreateDB() 'mdb를 생성한다.
Dim TestDB As Database
Set TestDB = CreateDatabase(PathDB, dbLangGeneral)
With TestDB
.Execute "CREATE TABLE MenberTbl(MenberName TEXT (30), MenberSex TEXT (2), " & _
"MenberJumiNo TEXT (20), MenberTelno TEXT (20))" '이름,성별,주민번호, 전화번호
.Close
End With
Set TestDB = Nothing
End Function
Private Sub Form_Unload(Cancel As Integer)
DB.Close
Set DB = Nothing
End Sub
일반적으로 DB는 엑세스로 직접 디자인해 만드나 여기서는
DB가 없으면 자동 생성하도록 하였습니다,
잘 보시면 DB필드나 DB명 등을 변경할수 있습니다,
참고하시고 많은 공부 되시길....
0 Comments:
Post a Comment
<< Home