Option Explicit
Public recCustomers As Recordset
Dim blnRecordEdited As Boolean
Dim blnAddMode As Boolean
Dim strSqlAmtDue As String
Public retid As String
Private Sub cmdAdd_Click()
blnAddMode = True
ClearControls
ChangeCommandButtons
txtName.SetFocus
End Sub
Private Sub ClearControls()
txtName =
""
txtAddress =
""
txtTown =
""
txtCounty =
""
txtCode =
""
txtNumber =
""
End Sub
Private Sub ChangeCommandButtons()
cmdUpdate.Enabled =
True
cmdUpdate.Default =
True
cmdAdd.Enabled =
False
If blnAddMode =
True Then
cmdDelete.Enabled = False
End If
End Sub
Private Sub cmdCode_Click()
On Error Resume
Next
Dim Key As String
Key =
frmSearch.Search("select * from customers where Zip like")
recCustomers.Close
If Key <>
"" Then
Set recCustomers
= GDBRecordset("select * from customers where zip like '" & Key
& "'")
Else
Set recCustomers
= GDBRecordset("select * from customers")
End If
End Sub
Private Sub cmdCounty_Click()
On Error Resume
Next
Dim Key As String
Key =
frmSearch.Search("select * from customers where county like")
recCustomers.Close
If Key <>
"" Then
Set recCustomers
= GDBRecordset("select * from customers where county like '" &
Key & "'")
Else
Set recCustomers
= GDBRecordset("select * from customers")
End If
End Sub
Private Sub cmdName_Click()
On Error Resume
Next
Dim Key As String
Key =
frmSearch.Search("select * from customers where Cust_name like")
recCustomers.Close
If Key <>
"" Then
Set recCustomers
= GDBRecordset("select * from customers where cust_name like '" &
Key & "'")
Else
Set recCustomers
= GDBRecordset("select * from customers")
End If
End Sub
Private Sub cmdNavigate_Click(Index As Integer)
recVerify
Select Case Index
Case 0
recCustomers.MoveFirst
Case 1
recCustomers.MovePrevious
If
recCustomers.BOF = True Then
recCustomers.MoveFirst
End If
Case 2
recCustomers.MoveNext
If
recCustomers.EOF = True Then
recCustomers.MoveLast
End If
Case 3
recCustomers.MoveLast
End Select
loadcontrols
EnableNavigation
InitializeCommandButtons
blnRecordEdited =
False
txtName.SetFocus
End Sub
Private Sub cmdUpdate_Click()
recVerify
If blnAddMode =
True Then
recCustomers.AddNew
Else
recCustomers.Edit
End If
loadbuffer
recCustomers.Update
If blnAddMode =
True Then
recCustomers.Bookmark = recCustomers.LastModified
ClearControls
End If
EnableNavigation
InitializeCommandButtons
blnRecordEdited
= False
txtName.SetFocus
End Sub
Private Sub loadbuffer()
recCustomers!Cust_Name = txtName
recCustomers!Address = txtAddress
recCustomers!Town =
txtTown
recCustomers!County
= txtCounty
recCustomers!Cust_no = Val(txtNumber)
End Sub
Private Sub cmdDelete_click()
recVerify
Dim strResponse As
String
strResponse =
MsgBox("Are you sure you want to delete this record?", vbYesNo +
vbDefaultButton2, "Delete Confirmation")
If strResponse =
vbYes Then
recCustomers.Delete
recCustomers.MoveNext
If
recCustomers.EOF = True Then recCustomers.MoveLast
loadcontrols
EnableNavigation
InitializeCommandButtons
blnRecordEdited =
False
txtName.SetFocus
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As
Integer)
If KeyCode =
vbKeyEscape Then
loadcontrols
EnableNavigation
InitializeCommandButtons
blnRecordEdited =
False
blnAddMode =
False
End If
End Sub
Private Sub cmdClose_Click()
Unload frmCustomer
End
End Sub
Private Sub txtAddress_Change()
If blnRecordEdited
= False Then
ChangeCommandButtons
DisableNavigation
blnRecordEdited
= True
End If
End Sub
Private Sub txtCode_Change()
If blnRecordEdited
= False Then
ChangeCommandButtons
DisableNavigation
blnRecordEdited
= True
End If
End Sub
Private Sub txtCounty_Change()
If blnRecordEdited
= False Then
ChangeCommandButtons
DisableNavigation
blnRecordEdited
= True
End If
End Sub
Private Sub txtName_Change()
If blnRecordEdited
= False Then
ChangeCommandButtons
DisableNavigation
blnRecordEdited
= True
End If
End Sub
Private Sub Form_Load()
GDBOpen
("C:\Program Files\Microsoft Visual Studio\VB98\50KCAR.MDB")
Set recCustomers =
GDBRecordset("select * from customers")
loadcontrols
EnableNavigation
InitializeCommandButtons
blnRecordEdited =
False
blnAddMode = False
End Sub
Public Sub Back(retid As String)
Set recCustomers = GDBRecordset("select
* from Customers where cust_no = " & retid)
loadcontrols
EnableNavigation
InitializeCommandButtons
blnRecordEdited =
False
blnAddMode = False
End Sub
Private Sub loadcontrols()
txtName =
recCustomers!Cust_Name
txtAddress =
recCustomers!Address
txtTown =
recCustomers!Town
If
IsNull(recCustomers!County) Then
txtCounty =
""
Else
txtCounty =
recCustomers!County
End If
If
IsNull(recCustomers.Fields(5)) Then
txtCode = ""
Else
txtCode =
recCustomers.Fields(5)
End If
txtNumber =
recCustomers!Cust_no
End Sub
Private Sub EnableNavigation()
cmdNavigate(0).Enabled = True
cmdNavigate(1).Enabled = True
cmdNavigate(2).Enabled = True
cmdNavigate(3).Enabled
= True
End Sub
Private Sub InitializeCommandButtons()
cmdUpdate.Enabled =
False
cmdUpdate.Default =
False
cmdAdd.Enabled =
True
cmdDelete.Enabled =
True
End Sub
Private Sub Form_Unload(Cancel As Integer)
GDBClose
End Sub
Private Sub txtNumber_Change()
If blnRecordEdited
= False Then
ChangeCommandButtons
DisableNavigation
blnRecordEdited
= True
End If
End Sub
Private Sub txtTown_Change()
If blnRecordEdited
= False Then
ChangeCommandButtons
DisableNavigation
blnRecordEdited
= True
End If
End Sub
Private Sub DisableNavigation()
cmdNavigate(0).Enabled = False
cmdNavigate(1).Enabled = False
cmdNavigate(2).Enabled = False
cmdNavigate(3).Enabled = False
End Sub
Private Sub recVerify()
If
recCustomers.AbsolutePosition = -1 Then
Set
recCustomers = GDBRecordset("Select * from Customers")
recCustomers.FindFirst ("Cust_Name='" & txtName.Text &
"'")
End If
End Sub