Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 31

SAMPLE SOURCE CODE

Login

Private Sub cmdCancel_Click()

End

End Sub

Private Sub cmdOK_Click()

If txtUserName = "admin" Then

If txtPassword = "admin" Then

Me.Hide

MDIForm1.Show

Else

MsgBox "Wrong Password"

txtPassword.Text = ""

txtPassword.SetFocus

End If

Else

If txtUserName = "" Or txtPassword = "" Then

MsgBox "Please Enter Username or Password"

Else

MsgBox "Please Enter valid User or Password, Try again!", , "Login"

txtUserName = ""
txtPassword = ""

txtUserName.SetFocus

SendKeys "{Home}+{End}"

End If

End If

End Sub

Train Details:

Option Explicit

Dim rs1 As New ADODB.Recordset

Dim rs As New ADODB.Recordset

Private Sub cmdCancel_Click()

Adodc.Recordset.CancelUpdate

Adodc.Recordset.MoveFirst

cmdNew.Enabled = True

cmdUpdate.Enabled = True

cmdSave.Enabled = True

cmdFirst.Enabled = True

cmdPrev.Enabled = True

cmdNext.Enabled = True

cmdLast.Enabled = True
txtlock

End Sub

Private Sub cmdDel_Click()

Dim a As Variant

a = MsgBox("Are you sure to Delete this Train Details", vbCritical + vbYesNo, "Delete Train")

If a = vbYes Then

rs.Delete

MsgBox "Deleted"

End If

End Sub

Private Sub cmdFirst_Click()

rs.MoveFirst

txtSetFields

End Sub

Private Sub cmdLast_Click()

rs.MoveLast

txtSetFields

End Sub

Private Sub cmdNext_Click()

rs.MoveNext

txtSetFields
End Sub

Private Sub cmdNew_Click()

rs.AddNew

txtClear

cmdNew.Enabled = False

cmdSave.Enabled = True

cmdCancel.Enabled = True

End Sub

Private Sub gets()

rs(0) = txtTrNo.Text

rs(1) = txtTrName.Text

rs(2) = NotAvl.Text

rs(3) = txtSt_stat.Text

rs(4) = txtVia.Text

rs(5) = txtEnd_stat.Text

rs(6) = txtDept_time.Text

rs(7) = txtIIAC.Text

rs(8) = txtIIIAc.Text

rs(9) = txtAcCh.Text

rs(10) = txtICls.Text

rs(11) = txtIICls.Text
rs(12) = txtGen.Text

End Sub

Private Sub cmdOK_Click()

Unload Me

End Sub

Private Sub cmdPrev_Click()

Adodc.Recordset.MovePrevious

txtSetFields

End Sub

Private Sub puts()

rs(0) = Val(txtTrNo.Text)

rs(1) = txtTrName.Text

rs(2) = NotAvl.Text

rs(3) = txtSt_stat.Text

rs(4) = txtVia.Text

rs(5) = txtEnd_stat.Text

rs(6) = CDate(txtDept_time.Text)

rs(7) = txtIIAC.Text

rs(8) = txtIIIAc.Text

rs(9) = txtAcCh.Text

rs(10) = txtICls.Text
rs(11) = txtIICls.Text

rs(12) = txtGen.Text

End Sub

Private Sub cmdSave_Click()

puts

rs.Update

MsgBox "Stored"

End Sub

Private Sub cmdupdate_Click()

gets

cmdUpdate.Enabled = False

cmdSave.Enabled = True

cmdCancel.Enabled = True

rs.Update

MsgBox "updated"

End Sub

Private Sub Form_Load()

'Call open_database

rs.Open "train_details", cn, adOpenDynamic, adLockOptimistic

End Sub

Public Sub txtClear()


txtTrNo.Text = ""

txtTrName.Text = ""

NotAvl.Text = "-"

txtSt_stat.Text = ""

txtVia.Text = ""

txtEnd_stat.Text = ""

txtDept_time.Text = ""

txtIIAC.Text = "0"

txtIIIAc.Text = "0"

txtAcCh.Text = "0"

txtICls.Text = "0"

txtIICls.Text = "0"

txtGen.Text = "0"

End Sub

Public Sub txtSetFields()

If rs.BOF = True Then

MsgBox "First Record", vbCritical

cmdPrev.Enabled = False

ElseIf rs.EOF = True Then

MsgBox "Last Record", vbCritical

cmdNext.Enabled = False
Else

txtTrNo.Text = rs.Fields(0).Value

txtTrName.Text = rs.Fields(1).Value

NotAvl.Text = rs.Fields(2).Value

txtSt_stat.Text = rs.Fields(3).Value

txtVia.Text = rs.Fields(4).Value

txtEnd_stat.Text = rs.Fields(5).Value

txtDept_time.Text = rs.Fields(6).Value

txtIIAC.Text = rs.Fields(7).Value

txtIIIAc.Text = rs.Fields(8).Value

txtAcCh.Text = rs.Fields(9).Value

txtICls.Text = rs.Fields(10).Value

txtIICls.Text = rs.Fields(11).Value

txtGen.Text = rs.Fields(12).Value

End If

End Sub

Public Sub check_position()

If rs.AbsolutePosition = 1 Then

cmdFirst.Enabled = False

cmdPrev.Enabled = False

cmdNext.Enabled = True
cmdLast.Enabled = True

ElseIf rs.AbsolutePosition = Adodc.Recordset.RecordCount Then

cmdFirst.Enabled = True

cmdPrev.Enabled = True

cmdNext.Enabled = False

cmdLast.Enabled = False

ElseIf rs.RecordCount = 0 Then

cmdFirst.Enabled = False

cmdPrev.Enabled = False

cmdNext.Enabled = False

cmdLast.Enabled = False

Else

cmdFirst.Enabled = True

cmdPrev.Enabled = True

cmdNext.Enabled = True

cmdLast.Enabled = True

End If

End Sub

Private Sub Form_Unload(Cancel As Integer)

rs.Close

End Sub
Seat Available:

Dim rs As New ADODB.Recordset

Dim rs1 As New ADODB.Recordset

Private Sub cmdOK_Click()

Unload Me

End Sub

'Option Explicit

Private Sub Form_Load()

'TRNO.Text = TRNO.List(0)

txtlock

'Call open_database

rs.Open "train_details", cn, adOpenDynamic, adLockOptimistic

While rs.EOF = False

TRNO.AddItem (rs(0))

rs.MoveNext

Wend

End Sub

Private Sub Form_Unload(Cancel As Integer)

rs.Close

End Sub

Private Sub TRNO_Click()


rs.Close

MsgBox TRNO.Text

Dim i As Integer

i = CInt(TRNO.Text)

rs.Open "select * from train_details where tr_no = " & i

txtSetFields

End Sub

Public Sub txtlock()

txtTrName.Locked = True

txtIIAC.Locked = True

txtIIIAc.Locked = True

txtAcCh.Locked = True

txtICls.Locked = True

txtIICls.Locked = True

txtGen.Locked = True

End Sub

Public Sub txtUnlock()

TRNO.Locked = False

txtTrName.Locked = False

txtIIAC.Locked = False

txtIIIAc.Locked = False
txtAcCh.Locked = False

txtICls.Locked = False

txtIICls.Locked = False

txtGen.Locked = False

End Sub

Public Sub txtClear()

TRNO.Text = ""

txtTrName.Text = ""

txtIIAC.Text = "0"

txtIIIAc.Text = "0"

txtAcCh.Text = "0"

txtICls.Text = "0"

txtIICls.Text = "0"

txtGen.Text = "0"

End Sub

Public Sub txtSetFields()

txtTrName.Text = rs.Fields(1).Value

lblSt_Stat.Caption = rs.Fields(3).Value

lblEnd_Stat.Caption = rs.Fields(5).Value

tim.Caption = rs.Fields(6).Value

txtIIAC.Text = rs.Fields(7).Value
txtIIIAc.Text = rs.Fields(8).Value

txtAcCh.Text = rs.Fields(9).Value

txtICls.Text = rs.Fields(10).Value

txtIICls.Text = rs.Fields(11).Value

txtGen.Text = rs.Fields(12).Value

End Sub

Passenger Details:

Private Sub DBGrid1_KeyPress(KeyAscii As Integer)

If KeyAscii = 27 Then

Unload Me

End If

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)

If KeyAscii = 27 Then

Unload Me

End If

End Sub

Reservation Booking:

Dim rs1 As New ADODB.Recordset


Dim rs As New ADODB.Recordset

Dim rs2 As New ADODB.Recordset

Dim rs3 As New ADODB.Recordset

Private Sub Add1_KeyPress(KeyAscii As Integer)

If KeyAscii > 96 And KeyAscii < 123 Then

KeyAscii = KeyAscii - 32

End If

End Sub

Private Sub Add2_KeyPress(KeyAscii As Integer)

If KeyAscii > 96 And KeyAscii < 123 Then

KeyAscii = KeyAscii - 32

End If

End Sub

Private Sub AGE_KeyPress(KeyAscii As Integer)

If KeyAscii < 48 Or KeyAscii > 58 Then

If KeyAscii = 8 Then

Else

KeyAscii = 0

End If

End If

End Sub
Private Sub Bord_to_KeyPress(KeyAscii As Integer)

If KeyAscii > 96 And KeyAscii < 123 Then

KeyAscii = KeyAscii - 32

End If

End Sub

Private Sub City_KeyPress(KeyAscii As Integer)

If KeyAscii > 96 And KeyAscii < 123 Then

KeyAscii = KeyAscii - 32

End If

End Sub

Private Sub cmdexit_Click()

Unload Me

End Sub

Private Sub Form_Unload(Cancel As Integer)

'rs1.Close

'rs3.Close

'cn.Close

End Sub

Private Sub SEX_KeyPress(KeyAscii As Integer)

If KeyAscii > 96 And KeyAscii < 123 Then

KeyAscii = KeyAscii - 32
End If

End Sub

Private Sub SEX_LostFocus()

If SEX.Text = "MALE" Or SEX.Text = "FEMALE" Then

Else

MsgBox "Please Sex Type : MALE / FEMALE", vbCritical, "Sex Type"

SEX.Text = ""

SEX.SetFocus

End If

End Sub

Private Sub Class_Type_Click()

rs1.CursorLocation = adUseClient

rs1.Open "select* from station_fare where st_name ='" & st_stat.Text & "' and end_name ='" &
end_stat.Text & "'"

'rs1.Open "select fare from station_fare where st_name='" & St_stat.Text & " ' and end_name='"
& end_stat.Text & "' and class_type='" & Class_type.Text & "'"

'fare.Text = rs1.Fields(0)

rs1.MoveFirst

If Class_Type.Text = "II Ac" Then

fare.Text = rs1.Fields(3).Value

couch.Text = "AC-II"

ElseIf Class_Type.Text = "III Ac" Then


fare.Text = rs1.Fields(4).Value

couch.Text = "AC-III"

ElseIf Class_Type.Text = "Ac Chair" Then

'fare.Text = rs1.Fields(5).Value

couch.Text = "Ac-CH"

ElseIf Class_Type.Text = "I Class" Then

fare.Text = rs1.Fields(6).Value

couch.Text = "F"

ElseIf Class_Type.Text = "II Class" Then

fare.Text = rs1.Fields(7).Value

couch.Text = "S"

ElseIf Class_Type.Text = "UnReserved" Then

fare.Text = rs1.Fields(8).Value

couch.Text = "Gen"

End If

End Sub

Private Sub cmdSave_Click()

rs3.Open "reservation", cn, adOpenDynamic, adLockOptimistic

rs3.AddNew

rs3(0) = P_cd.Text

rs3(1) = P_nm.Text
rs3(2) = AGE.Text

rs3(3) = SEX.Text

rs3(4) = TRNO.Text

rs3(5) = tr_name.Text

rs3(6) = dept_tm.Text

rs3(7) = DTPicker1.Value

rs3(8) = st_stat.Text

rs3(9) = end_stat.Text

rs3(10) = Bord_to.Text

rs3(11) = Class_Type.Text

rs3(12) = fare.Text

rs3(13) = couch.Text

rs3(14) = seatNo.Text

rs3.Update

MsgBox "Stored"

'rs.Source = "select * from train_details"

'rs.Open

'rs1.Open "select * from train_details"

'If Class_type = "II Ac" Then

'MsgBox rs1.Fields(7).Value
' If rs1.Fields(7).Value = 0 Then

' MsgBox "Sorry Reservation is Full"

' Exit Sub

' Else

' rs1.Source = "update train_details set II_Ac_Seats = " & Val(rs.Fields(7).Value) - 1 & "
where tr_name = " & tr_name.Text

' rs1.Open

' End If

'ElseIf Class_type = "III Ac" Then

'MsgBox rs.Fields(8).Value

' If rs.Fields(8).Value = 0 Then

' MsgBox "Sorry Reservation is Full"

' Exit Sub

' Else

' rs1.Source = "update train_details set III_Ac_Seats = " & Val(rs.Fields(8).Value) - 1 & "
where tr_name = " & tr_name.Text

' rs1.Open

' End If

'ElseIf Class_type = "Ac Chair" Then

'MsgBox rs1.Fields(9).Value

' If rs1.Fields(9).Value = 0 Then

' MsgBox "Sorry Reservation is Full"


' Exit Sub

' Else

' rs1.Source = "update train_details set Ac_Chair_Seats = " & Val(rs.Fields(9).Value) - 1 &
" where tr_name = '" & tr_name.Text & "'"

' rs1.Open

' End If

'ElseIf Class_type = "I Class" Then

'MsgBox rs.Fields(10).Value

' If rs.Fields(10).Value = 0 Then

' MsgBox "Sorry Reservation is Full"

' Exit Sub

' Else

' rs1.Source = "update train_details set I_Class_Seats = " & Val(rs.Fields(10).Value) - 1 & "
where tr_name = " & tr_name.Text

' rs1.Open

' End If

'ElseIf Class_type = "II Class" Then

'MsgBox rs.Fields(11).Value

' If rs.Fields(11).Value = 0 Then

' MsgBox "Sorry Reservation is Full"

' Exit Sub

' Else
' rs1.Source = "update train_details set II_Class_Seats = " & Val(rs.Fields(11).Value) - 1 & "
where tr_name = " & tr_name.Text

' rs1.Open

' End If

'ElseIf Class_type = "UnReserved" Then

'MsgBox rs.Fields(12).Value

' If rs.Fields(12).Value = 0 Then

' MsgBox "Sorry Reservation is Full"

' Exit Sub

' Else

' rs1.Source = "update train_details set UnResrv_Seats = " & Val(rs.Fields(12).Value) - 1 &
" where tr_name = " & tr_name.Text

' rs1.Open

' End If

'End If'

'qry = "insert into Passenger_Details values('" & P_cd.Text & "','" & P_nm.Text & "','" &
Add1.Text & "','" _

'& Add2.Text & "','" & City.Text & "','" & pin.Text & "','" & ph.Text & "','" & AGE.Text & "','"
_

'& SEX.Text & "')"

'Set rec = con.Execute(qry)'

'qry = "insert into Reservation values('" & P_cd.Text & "','" & P_nm.Text & "','" & AGE.Text &
"','" _
'& SEX.Text & "','" & trno.Text & "','" & tr_name.Text & "','" & dept_tm.Text & "','" &
J_dt.Value & "','" _

'& St_stat.Text & "','" & end_stat.Text & "','" & Bord_to.Text & "','" & Class_type.Text & "','" &
fare.Text & "','" & couch.Text & "'," & seatNo.Text & ")"

'Set rec = con.Execute(qry)

''cmdSave.Enabled = False'

'rs.Close

End Sub

Private Sub Form_Load()

Call open_database

rs1.Open "select tr_no from train_details", cn, adOpenDynamic, adLockOptimistic

rs1.MoveFirst
TRNO.Clear

While rs1.EOF = False

TRNO.AddItem (rs1.Fields(0).Value)

rs1.MoveNext

Wend

rs1.Close

J_dt = Format(Date, "dd-MM-yyyy")

Class_Type.AddItem ("II Ac")

Class_Type.AddItem ("III Ac")

Class_Type.AddItem ("Ac Chair")

Class_Type.AddItem ("I Class")

Class_Type.AddItem ("II Class")

Class_Type.AddItem ("UnReserved")

cmdSave.Enabled = True

txtlock

End Sub

Public Sub txtlock()

P_cd.Locked = False

tr_name.Locked = True

dept_tm.Locked = True

st_stat.Locked = True
end_stat.Locked = True

fare.Locked = False

couch.Locked = True

End Sub

Public Sub txtUnlock()

P_cd.Locked = False

tr_name.Locked = False

dept_tm.Locked = False

st_stat.Locked = False

end_stat.Locked = False

fare.Locked = False

couch.Locked = False

End Sub

Public Sub txtClear()

P_cd.Text = ""

P_nm.Text = ""

AGE.Text = ""

SEX.Text = ""

Add1.Text = ""

Add2.Text = ""

City.Text = ""
pin.Text = ""

ph.Text = ""

tr_name.Text = ""

dept_tm.Text = ""

st_stat.Text = ""

end_stat.Text = ""

Bord_to.Text = ""

fare.Text = ""

couch.Text = ""

seatNo.Text = ""

End Sub

Public Sub txtSetFields()

If rs.BOF = True Then

MsgBox "First Record", vbCritical

cmdPrev.Enabled = False

ElseIf rs.EOF = True Then

MsgBox "Last Record", vbCritical

cmdNext.Enabled = False

Else

txtTrNo.Text = rs.Fields(0).Value

txtTrName.Text = rs.Fields(1).Value
NotAvl.Text = rs.Fields(2).Value

txtSt_stat.Text = rs.Fields(3).Value

txtVia.Text = rs.Fields(4).Value

txtEnd_stat.Text = rs.Fields(5).Value

txtDept_time.Text = rs.Fields(6).Value

txtIIAC.Text = rs.Fields(7).Value

txtIIIAc.Text = rs.Fields(8).Value

txtAcCh.Text = rs.Fields(9).Value

txtICls.Text = rs.Fields(10).Value

txtIICls.Text = rs.Fields(11).Value

txtGen.Text = rs.Fields(12).Value

End If

End Sub

Private Sub TRNO_Click()

Dim k As Integer

k = CInt(TRNO.Text)

rs1.Open "select * from Train_details where tr_no = " & k

tr_name.Text = rs1.Fields(1).Value

st_stat.Text = rs1.Fields(3).Value

end_stat.Text = rs1.Fields(5).Value

dept_tm.Text = rs1.Fields(6).Value
rs1.Close

End Sub

Private Sub cmdCancel_Click()

MsgBox "Reservation is not Booked ???", vbCritical

Unload Me

End Sub

Cancel Reservation:

Dim rs1 As New ADODB.Recordset

Dim rs2 As New ADODB.Recordset

Option Explicit

Private Sub cmdCancel_Click()

rs1.Close

rs2.Open "select * from train_details", cn, adOpenDynamic, adLockPessimistic

rs1.Open "delete from reservation where p_code = '" & P_cd.Text & "'"

'Set rec = con.Execute(qry)

'rs2.open "delete from pass_details where p_code = '" & P_cd.Text & "'"

'Set rec = con.Execute(qry)

If Class_type = "II Ac" Then

rs1.Source = "update train_details set II_Ac_Seats = " & Val(rs2.Fields(7).Value) + 1 & "
where tr_name = '" & tr_name.Text & "'"

rs1.Open
ElseIf Class_type = "III Ac" Then

rs1.Source = "update train_details set III_Ac_Seats = " & Val(rs2.Fields(8).Value) + 1 & "
where tr_name = " & tr_name.Text

rs1.Open

ElseIf Class_type = "Ac Chair" Then

rs1.Source = "update train_details set Ac_Chair_Seats = " & Val(rs2.Fields(9).Value) + 1


& " where tr_name = '" & tr_name.Text & "'"

rs1.Open

ElseIf Class_type = "I Class" Then

rs1.Source = "update train_details set I_Class_Seats = " & Val(rs2.Fields(10).Value) + 1 &


" where tr_name = " & tr_name.Text

rs1.Open

ElseIf Class_type = "II Class" Then

rs1.Source = "update train_details set II_Class_Seats = " & Val(rs2.Fields(11).Value) + 1 &


" where tr_name = " & tr_name.Text

rs1.Open

ElseIf Class_type = "UnReserved" Then

rs1.Source = "update train_details set UnResrv_Seats = " & Val(rs2.Fields(12).Value) + 1


& " where tr_name = " & tr_name.Text

rs1.Open

End If

cmdCancel.Enabled = False

MsgBox " Cancelled"


End Sub

Private Sub cmdexit_Click()

Unload Me

End Sub

Private Sub Form_Load()

'Call open_database

'rs1.Close

rs1.Open "select P_Code from reservation", cn, adOpenDynamic, adLockOptimistic

rs1.MoveFirst

P_cd.Clear

While rs1.EOF = False

P_cd.AddItem (rs1.Fields(0).Value)

rs1.MoveNext

Wend

cmdCancel.Enabled = True

rs1.Close

End Sub

Private Sub P_cd_Click()

rs1.Open "select * from reservation where p_code = '" & P_cd.Text & "'"

P_nm.Text = rs1(1)

AGE.Text = rs1(2)
SEX.Text = rs1(3)

trno.Text = rs1(4)

tr_name.Text = rs1(5)

dept_tm.Text = rs1(6)

J_dt.Text = Format(rs1(7), "d-MMM-yyyy")

st_stat.Text = rs1(8)

end_stat.Text = rs1(9)

Bord_to.Text = rs1(10)

Class_type.Text = rs1(11)

fare.Text = rs1(12)

couch.Text = rs1(13)

seatNo.Text = rs1(14)

End Sub
BIBILOGRAPHY

Books
1. Mastering in Visual Basic 6.0
- Even Gelo Petroutsos
2. Programming in Visual Basic 6.0
- Htozer
3. Murchis Visual Basic 6.0
- Edloop, Anne Prince, Joel Murach
4. Introduction to MS-Access
- Nancy Greeberg
- Priya Nathan
WEBSITES
MICROSOFT VISUAL BASIC 6.0
1. www.visualbasic/(S(pdfrohu0ajmwt445fanvj2r3))/learn/data-access/
2. www.w3schools.com/vb/default.asp
3. www.411visualbasic /home/sites
4. www.cristiandarie.ro/vb-tutorial/
5. Www. visualbasic -tutorials.com/basics/first-website/

MS ACCESS
1. www.functionx.com/msaccess/
2. www.technet.microsoft.com/en-us/library/ msaccess69620.aspx
3. www.msdn.microsoft.com/en-us/library/ms169620(msaccess).aspx
4. www.softwaretrainingtutorials.com/ms- access -2005.php

You might also like