You are on page 1of 5

SAMPLE CODINGS

Option Explicit Dim ans Private Sub cmdAdd_Clic !" clear_all_fields 'frame fra_ci(0).Enabled = True fra_ci(1).Enabled = True txt_Firstname.SetFocus 'controls cmdAdd.Enabled = False cmdSave.Enabled = True cmd ancel.Enabled = True ustomer_!umber End Sub Private Sub cmdCancel_Clic !" 'frame fra_ci(0).Enabled = False fra_ci(1).Enabled = False 'controls cmdAdd.Enabled = True cmdSave.Enabled = False cmd ancel.Enabled = False clear_all_fields End Sub Private Sub cmdClose_Clic !" "nload #e End Sub Private Sub cmdSave_Clic !" $f txt_Firstname = %% T&en #s'(ox % annot save if Firstname is em)t*.%+ vbExclamation+ %Firstname is missin'% txt_Firstname.SetFocus Exit Sub End $f

$f txt_#$ = %% T&en #s'(ox % annot save if #iddle $nitial is em)t*.%+ vbExclamation+ %#iddle $nitial is missin'% txt_#$.SetFocus Exit Sub End $f $f txt_,astname = %% T&en #s'(ox % annot save if ,astname is em)t*.%+ vbExclamation+ %,astname is missin'% txt_,astname.SetFocus Exit Sub End $f $f txt_StreetAddress = %% T&en #s'(ox % annot save if Street Address is em)t*.%+ vbExclamation+ %Street Address is missin'% txt_StreetAddress.SetFocus Exit Sub End $f $f txt_ it* = %% T&en #s'(ox % annot save if it* or To-n is em)t*.%+ vbExclamation+ % it* or To-n is missin'% txt_ it*.SetFocus Exit Sub End $f $f txt_.rovince = %% T&en #s'(ox % annot save if .rovince is em)t*.%+ vbExclamation+ %.rovince is missin'% txt_.rovince.SetFocus Exit Sub End $f $f txt_/i).Text 01 %% T&en $f $s!umeric(txt_/i)) = False T&en #s'(ox %$nvalid /i) ode. !umbers onl*.%+ vbExclamation+ %$nvalid /i) ode% txt_/i).SetFocus Send2e*s %3&ome4% 5 %3end4% Exit Sub End $f End $f $f txt_ ontact!umber 01 %% T&en $f $s!umeric(txt_ ontact!umber) = False T&en #s'(ox %$nvalid ontact number. !umbers onl*.%+ vbExclamation+ %$nvalid contact number% txt_ ontact!umber.SetFocus Send2e*s %3&ome4% 5 %3end4% Exit Sub End $f End $f $f txt_(irt&date = %% T&en

#s'(ox % annot save if (irt&date is em)t*.%+ vbExclamation+ %(irt&date is missin'% txt_(irt&date.SetFocus Exit Sub End $f $f combo_Sex = %% T&en #s'(ox % annot save if 6ender is em)t*.%+ vbExclamation+ %6ender is missin'% combo_Sex.SetFocus Exit Sub End $f $f #s'(ox(% onfirm save ne- customer record.%+ vb7uestion 8 vb9es!o) = vb9es T&en :it& ;ata1.<ecordset .Add!e= ust_Firstname = txt_Firstname.Text = ust_#$ = txt_#$.Text = ust_,astname = txt_,astname.Text = ust_StreetAddress = txt_StreetAddress.Text = ust_ it* = txt_ it*.Text = ust_.rovince = txt_.rovince.Text = ust_/i) = Trim(txt_/i).Text) = ust_ ontact!umber = Trim(txt_ ontact!umber.Text) = ust_birt&date = txt_(irt&date.Text = ust_sex = combo_Sex.Text = ust_remar>s = txt_<emar>s.Text = ust_!umber = lbl_ ustomer!umber. a)tion .")date End :it& ;ata1.<efres& #s'(ox %!e- customer record saved.%+ vb$nformation End $f 'frame fra_ci(0).Enabled = False fra_ci(1).Enabled = False 'controls cmdAdd.Enabled = True cmdSave.Enabled = False cmd ancel.Enabled = False clear_all_fields End Sub

Private Sub #orm_Load!" ;ata1.;atabase!ame = A))..at& 5 %? #@.mdb% ;ata1.<ecordSource = %select A from tbl ustomer order b* ust_!umber% ;ata1.<efres& combo_Sex. lear combo_Sex.Add$tem %#ale% combo_Sex.Add$tem %Female% End Sub Private Sub clear_all_$ields!" txt_Firstname.Text = %% txt_#$.Text = %% txt_,astname.Text = %% txt_StreetAddress.Text = %% txt_ it*.Text = %% txt_.rovince.Text = %% txt_/i).Text = %% txt_ ontact!umber.Text = %% txt_(irt&date.Text = %% combo_Sex.Text = %% txt_<emar>s.Text = %% lbl_ ustomer!umber. a)tion = %BBBBB% End Sub Private Sub Customer_Number!" ;im container1 ;im ust ode ust ode = % C0% ust ode = % C% 5 $nt(#id( ust ode+ D)) 8 1 ;ata1.<ecordSource = %select A from tbl ustomer -&ere ust_!umber = '% 5 ust ode 5 %'% ;ata1.<efres& :&ile ;ata1.<ecordset.<ecord ount 01 0 $f ;ata1.<ecordset.<ecord ount 01 0 T&en ust ode = % C% 5 $nt(#id( ust ode+ D)) 8 1 End $f ;ata1.<ecordSource = %select A from tbl ustomer -&ere ust_!umber= '% 5 ust ode 5 %'% ;ata1.<efres& :end

lbl_ ustomer!umber = ust ode ;ata1.;atabase!ame = A))..at& 5 %? #@.mdb% ;ata1.<ecordSource = %select A from tbl ustomer order b* ust_!umber% ;ata1.<efres& End Sub

You might also like