Visual Basic Tutorial Lesson 29 - Creating Advanced VB Database Application Using ADO Control

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

7/8/2016

VisualBasicTutorialLesson29:CreatingAdvancedVBdatabaseapplicationusingADOcontrol

Lesson29:CreatingAdvancedVBdatabaseapplicationusingADOcontrol
<PreviousLesson><<Home>><NextLesson>
Adsby Google

VBVisualBasic

DatabaseSoftware

Login

ExcelTutorial

Inpreviouslessons,youhavelearnedhowtodesigndatabaseapplicationsusingdatacontrolandADOcontrol.However,thoseapplications
areverysimpleandplain.Inthislesson,youwilllearnhowtocreateamoreadvanceddatabaseapplicationusingADOcontrol.The
applicationyouaregoingtocreateisknownasanelectroniclibrary.Thiselectroniclibrarywillbeabletoaccepttheuserregistrationaswellas
handlinglogincommandthatrequiretheuser'spassword,thusenhancingthesecurityaspectofthedatabase.Basically,theapplicationwill
constituteawelcomemenu,aregistrationmenu,aLoginmenuandthemaindatabasemenu.Thesequenceofthemenusareillustratedas
follow:
Adsby Google

C#Code

VBAProgramming

RegistrationForm

VBTutorial

29.1TheWelcomeMenu
Firstofall,youneedtodesigntheWelcomemenu.Youcanfollowtheexampleasfollow:

http://www.vbtutor.net/lesson29.html

1/7

7/8/2016

VisualBasicTutorialLesson29:CreatingAdvancedVBdatabaseapplicationusingADOcontrol

Inthisform,youneedtoinsertthreecommandbuttonsandsettheirpropertiesasfollow:
ProperyName

Setting

Formname

main_menu

commandbutton1Name

cmdRegister

commandbutton1
Caption

Register

commandbutton2Name

cmdLogin

commandbutton2
Caption

Login

commandbutton3Name

cmdCancel

commandbutton3
Caption

Cancel

Thecodeisasfollows:
PrivateSubcmdCancel_Click()
End
EndSub
PrivateSubcmdLogin_Click()
main_menu.Hide
Login_form.Show
EndSub
PrivateSubcmdRegister_Click()
main_menu.Hide
Register.Show
EndSub

29.2TheRegistrationForm
IfanewuserclicktheRegisterbutton,theregistrationformwillappear.Anexampleisillustratedasfollow:

http://www.vbtutor.net/lesson29.html

2/7

7/8/2016

VisualBasicTutorialLesson29:CreatingAdvancedVBdatabaseapplicationusingADOcontrol

Thisregistrationformsconsistoftwotextboxes,threecommandbuttonsandanADOcontrol.Theirpropertiesaresetasfollow:
ProperyName

Setting

Formname

Register

textbox1name

txtName

textbox2name

txtpassword

textbox2PasswordChar

commandbutton1name

cmdConfirm

commandbutton1Caption

Confirm

commandbutton2name

cmdClear

commandbutton2Caption

Clear

commandbutton3name

cmdCancel

commandbutton3Caption

Cancel

ADOcontrolname

UserInfo

NotethatthePasswordCharoftextbox2issetas*whichmeansuserswillnotbeabletoseetheactualcharacterstheyenter,theywillonly
seethe*symbol.
Thecodeisasfollow:

PrivateSubcancel_Click()
End
EndSub
PrivateSubcmdClear_Click()
txtName.Text=""
txtpassword.Text=""
EndSub
PrivateSubcmdConfirm_Click()
UserInfo.Recordset.Fields("username")=txtName.Text
UserInfo.Recordset.Fields("password")=txtpassword.Text
UserInfo.Recordset.Update
Register.Hide
Login_form.Show
EndSub
PrivateSubForm_Load()
UserInfo.Recordset.AddNew
EndSub

<

29.3TheLoginMenu
http://www.vbtutor.net/lesson29.html

3/7

7/8/2016

VisualBasicTutorialLesson29:CreatingAdvancedVBdatabaseapplicationusingADOcontrol

29.3TheLoginMenu
TheLoginmenuisillustratedasfollow:

Therearetwotextboxesandacommandbutton,theirpropertiesaresetasfollow:
ProperyName

Setting

Textbox1name

txtName

Textbox2name

txtpassword

Commandbutton1name

cmdLogin

Commandbutton1
Caption

Login

Formname

Login_form

Thecodeisasfollow:

PrivateSubcmdLogin_Click()
DimusrnameAsString
DimpswordAsString
DimusernamAsString
DimpsswordAsString
DimMsgAsString

Register.UserInfo.Refresh
usrname=txtName.Text
psword=txtpassword.Text

DoUntilRegister.UserInfo.Recordset.EOF
IfRegister.UserInfo.Recordset.Fields("username").Value=usrnameAnd
Register.UserInfo.Recordset.Fields("password").Value=pswordThen
Login_form.Hide
frmLibrary.Show
ExitSub
Else
Register.UserInfo.Recordset.MoveNext
EndIf
Loop
Msg=MsgBox("Invalidpassword,tryagain!",vbOKCancel)
If(Msg=1)Then
Login_form.Show

http://www.vbtutor.net/lesson29.html

4/7

7/8/2016

VisualBasicTutorialLesson29:CreatingAdvancedVBdatabaseapplicationusingADOcontrol
txtName.Text=""
txtpassword=""
Else
End
EndIf
EndSub

29.4TheMainDatabaseManager
Themaindatabasemanagerisillustratedasfollow:

Thepropertiesofallcontrolsarelistedinthetablebelow:

PropertName

http://www.vbtutor.net/lesson29.html

Setting

Formname

frmLibrary

ADOcontrolname

adoLibrary

ADOvisible

False

TextBox1name

txtTitleA

TextBox2name

txtAuthor

TextBox3name

txtPublisher

TextBox4name

txtYear

TextBox5name

txtCategory

Commandbutton1name

cmdSave

Commandbutton1
caption

&Save

Commandbutton2name

cmdNew

Commandbutton2
caption

&New

5/7

7/8/2016

VisualBasicTutorialLesson29:CreatingAdvancedVBdatabaseapplicationusingADOcontrol
Commandbutton3name

cmdDelete

Commandbutton3
caption

&Delete

Commandbutton4name

cmdCancel

Commandbutton4
caption

&Cancel

Commandbutton5name

cmdNext

Commandbutton5
caption

N&ext

Commandbutton6name

cmdPrevious

Commandbutton6
caption

&Previous

Commandbutton7name

cmdExit

Commandbutton7
caption

E&xit

Thecodeisasfollow:

PrivateSubcmdCancel_Click()
txtTitle.Text=""
txtAuthor.Text=""
txtPublisher.Text=""
txtYear.Text=""
txtCategory.Text=""
EndSub
PrivateSubcmdDelete_Click()
Confirm=MsgBox("Areyousureyouwanttodeletethisrecord?",vbYesNo,"Deletion
Confirmation")
IfConfirm=vbYesThen
adoLibrary.Recordset.Delete
MsgBox"RecordDeleted!",,"Message"
Else
MsgBox"RecordNotDeleted!",,"Message"
EndIf
EndSub
PrivateSubcmdExit_Click()
End
EndSub
PrivateSubcmdNew_Click()
adoLibrary.Recordset.AddNew
EndSub
PrivateSubcmdNext_Click()
IfNotadoLibrary.Recordset.EOFThen
adoLibrary.Recordset.MoveNext
IfadoLibrary.Recordset.EOFThen

http://www.vbtutor.net/lesson29.html

6/7

7/8/2016

VisualBasicTutorialLesson29:CreatingAdvancedVBdatabaseapplicationusingADOcontrol
adoLibrary.Recordset.MovePrevious
EndIf
EndIf
EndSub
PrivateSubcmdPrevious_Click()
IfNotadoLibrary.Recordset.BOFThen
adoLibrary.Recordset.MovePrevious
IfadoLibrary.Recordset.BOFThen
adoLibrary.Recordset.MoveNext
EndIf
EndIf
EndSub
PrivateSubcmdSave_Click()
adoLibrary.Recordset.Fields("Title").Value=txtTitle.Text
adoLibrary.Recordset.Fields("Author").Value=txtAuthor.Text
adoLibrary.Recordset.Update
EndSub

Adsby Google

VBNet

DatabaseDesign

VBAMacroCode

AccessVB

<PreviousLesson><<Home>><NextLesson>
Copyright2008Dr.LiewVoonKiong.Allrightsreserved|Contact:admin@vbtutor.net

[PrivacyPolicy]

http://www.vbtutor.net/lesson29.html

7/7

You might also like