📄 vehicle.frm
字号:
VERSION 5.00
Begin VB.Form vehicle
BackColor = &H80000013&
Caption = "Vehicle Manager"
ClientHeight = 8865
ClientLeft = 60
ClientTop = 345
ClientWidth = 10905
LinkTopic = "Form1"
MDIChild = -1 'True
ScaleHeight = 8865
ScaleWidth = 10905
WindowState = 2 'Maximized
Begin VB.CommandButton cmdprevious
BackColor = &H00E0E0E0&
Caption = "&Previous"
Height = 495
Left = 5280
Style = 1 'Graphical
TabIndex = 15
Top = 4560
Width = 1215
End
Begin VB.CommandButton cmdnext
BackColor = &H00E0E0E0&
Caption = "&Next"
Height = 495
Left = 6720
Style = 1 'Graphical
TabIndex = 14
Top = 4560
Width = 1215
End
Begin VB.ComboBox cbodriver_ID
Height = 315
Left = 6240
TabIndex = 13
Top = 2880
Width = 3375
End
Begin VB.TextBox txtmodel
Appearance = 0 'Flat
Height = 285
Left = 6240
MaxLength = 10
TabIndex = 12
Top = 3600
Width = 3375
End
Begin VB.TextBox txtcode
Appearance = 0 'Flat
Height = 315
Left = 6240
Locked = -1 'True
TabIndex = 9
Top = 2160
Width = 3375
End
Begin VB.TextBox txtfuel
Appearance = 0 'Flat
Height = 285
Left = 6240
MaxLength = 6
TabIndex = 8
Top = 3240
Width = 3375
End
Begin VB.Frame Frame1
Appearance = 0 'Flat
BackColor = &H80000013&
Caption = "Options "
BeginProperty Font
Name = "Verdana"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 3375
Left = 10200
TabIndex = 5
Top = 2160
Width = 1695
Begin VB.CommandButton cmdadd
BackColor = &H00E0E0E0&
Caption = "&Add"
Height = 495
Left = 240
Style = 1 'Graphical
TabIndex = 17
Top = 360
Width = 1215
End
Begin VB.CommandButton cmdupdate
BackColor = &H00E0E0E0&
Caption = "&Update"
Height = 495
Left = 240
Style = 1 'Graphical
TabIndex = 16
Top = 1080
Width = 1215
End
Begin VB.CommandButton cmdexit
BackColor = &H00E0E0E0&
Caption = "&Exit"
Height = 495
Left = 240
Style = 1 'Graphical
TabIndex = 7
Top = 2520
Width = 1215
End
Begin VB.CommandButton cmddelete
BackColor = &H00E0E0E0&
Caption = "&Delete"
Height = 495
Left = 240
Style = 1 'Graphical
TabIndex = 6
Top = 1800
Width = 1215
End
End
Begin VB.TextBox txtreg_no
Appearance = 0 'Flat
Height = 300
Left = 6240
MaxLength = 8
TabIndex = 1
Top = 2520
Width = 3345
End
Begin VB.Image Image1
Height = 2160
Left = 120
Picture = "vehicle.frx":0000
Top = 120
Width = 2250
End
Begin VB.Label Label4
BackColor = &H00FFC0C0&
Caption = " Truck Code"
BeginProperty Font
Name = "Century Gothic"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 1
Left = 3600
TabIndex = 11
Top = 2160
Width = 2655
End
Begin VB.Label Label4
BackColor = &H00FFC0C0&
Caption = " Registration Number"
BeginProperty Font
Name = "Century Gothic"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 420
Index = 0
Left = 3600
TabIndex = 10
Top = 2520
Width = 2655
End
Begin VB.Label Label7
BackColor = &H00FFC0C0&
Caption = " Make/Model"
BeginProperty Font
Name = "Century Gothic"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 3600
TabIndex = 4
Top = 3600
Width = 2655
End
Begin VB.Label Label6
BackColor = &H00FFC0C0&
Caption = " Fuel Consumption (Lit/Km)"
BeginProperty Font
Name = "Century Gothic"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 420
Left = 3600
TabIndex = 3
Top = 3240
Width = 2655
End
Begin VB.Label Label5
BackColor = &H00FFC0C0&
Caption = " Driver ID"
BeginProperty Font
Name = "Century Gothic"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 420
Left = 3600
TabIndex = 2
Top = 2880
Width = 2655
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "Vehicle Manager"
BeginProperty Font
Name = "Verdana"
Size = 18
Charset = 0
Weight = 700
Underline = 0 'False
Italic = -1 'True
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 495
Left = 4800
TabIndex = 0
Top = 360
Width = 3615
End
End
Attribute VB_Name = "vehicle"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim cn As ADODB.Connection
Dim RS As ADODB.Recordset
Dim rs1 As ADODB.Recordset
Dim add As Boolean
Dim validated As Boolean
Dim vaccumated As Boolean
Private Sub CandyButton1_Click()
'call the command
Call cmdprevious_Click
End Sub
Private Sub CandyButton2_Click()
Call cmdnext_Click
End Sub
Private Sub cbodriver_ID_KeyPress(KeyAscii As Integer)
'disable changes
KeyAscii = 0
End Sub
Private Sub cmdadd_Click()
'add a record
add = True
clear
txtreg_no.SetFocus
End Sub
Private Sub cmdupdate_Click()
'ensure no blank fields
vaccumate
If vaccumated = False Then
Exit Sub
End If
validate
'ensure correct data types
If validated = False Then
Exit Sub
End If
'chek if new record or editing a current record
If add = True Then
add = False
RS.AddNew
save
RS.Update
MsgBox "The Record has been Saved"
RS.MoveLast
Display
Else
save
RS.Update
MsgBox "The Record has been Saved"
Display
End If
End Sub
Private Sub cmddelete_Click()
If RS.EOF = True And RS.BOF = True Then
MsgBox "Cannot delete Record", vbCritical, "Last Record"
Exit Sub
Else
On Error Resume Next
RS.Delete
clear
MsgBox "The Record has been Deleted"
RS.MoveFirst
Display
If Err Then
MsgBox Err.Number + Err.Description
End If
End If
End Sub
Private Sub cmdnext_Click()
On Error Resume Next
RS.MoveNext
Display
If RS.EOF = True Then
MsgBox "This is the last record"
RS.MovePrevious
End If
End Sub
Private Sub cmdprevious_Click()
On Error Resume Next
RS.MovePrevious
Display
If RS.BOF = True Then
MsgBox "This is the first record"
RS.MoveNext
End If
End Sub
Private Sub cmdexit_Click()
Unload Me
End Sub
Private Sub Form_Load()
On Error Resume Next
Set cn = New ADODB.Connection
Set RS = New ADODB.Recordset
Set cn1 = New ADODB.Connection
Set rs1 = New ADODB.Recordset
'connect to the database
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=TRANSPORT.MDB;Persist Security Info=False"
'open the record you intend to work with
RS.Open "select * from vehicle", cn, adOpenDynamic, adLockPessimistic
RS.MoveFirst
'add records to the combo box
popul8_combo
Display
If Err Then
MsgBox Err.Number + Err.Description, vbCritical, "Error"
End If
End Sub
Public Sub Display()
txtcode.Text = RS.Fields("truck_code")
txtreg_no.Text = RS.Fields("Reg_Number")
cbodriver_ID.Text = RS.Fields("Driver_ID")
txtfuel.Text = RS.Fields("Fuel_Consumption")
txtmodel.Text = RS.Fields("Name/Model")
End Sub
Public Sub clear()
txtcode.Text = ""
txtfuel.Text = ""
txtreg_no.Text = ""
cbodriver_ID = ""
txtmodel = ""
End Sub
Public Sub save()
RS("Fuel_Consumption") = txtfuel.Text
RS("Reg_Number") = txtreg_no.Text
RS("Driver_ID") = cbodriver_ID.Text
RS("Name/Model") = txtmodel.Text
End Sub
Public Sub popul8_combo()
Set rs1 = New ADODB.Recordset
rs1.Open "select * from driver", cn, adOpenDynamic, adLockPessimistic
Do
cbodriver_ID.AddItem rs1("Driver_ID")
rs1.MoveNext
Loop Until rs1.EOF = True
End Sub
Public Sub vaccumate()
If txtreg_no.Text = "" Then
Label4(0).ForeColor = vbRed
MsgBox "Registration No. of The Vehicle is required!", vbCritical, "Data Required!"
txtreg_no.SetFocus
vaccumated = False
Exit Sub
ElseIf cbodriver_ID.Text = "" Then
Label5.ForeColor = vbRed
MsgBox "The Vehicle's Driver is required!", vbCritical, "Data Required!"
vaccumated = False
Exit Sub
ElseIf txtfuel.Text = "" Then
Label8.ForeColor = vbRed
MsgBox "Fill in the fuel consumption of the Vehicle!", vbCritical, "Data Required!"
txtfuel.SetFocus
vaccumated = False
Exit Sub
ElseIf txtmodel.Text = "" Then
Label7.ForeColor = vbRed
MsgBox "What Model is the Vehicle?", vbCritical, "Data Required!"
txtmodel.SetFocus
vaccumated = False
Exit Sub
Else
vaccumated = True
End If
End Sub
Public Sub validate()
If Not IsNumeric(txtfuel.Text) Then
Label6.ForeColor = vbRed
MsgBox "Fuel consumption is needed in digits!!" & Chr(13) & "Honestly..???", vbCritical, "Datatype Mismatch."
txtfuel.SetFocus
SendKeys "{Home}+{End}"
validated = False
Exit Sub
Else
validated = True
End If
End Sub
Private Sub isButton1_Click()
RS.MoveFirst
Display
End Sub
Private Sub isButton2_Click()
RS.MoveLast
Display
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -