MsgBox "This is the first record !", vbExclamation, "Douglas Lads Club"
Else
SaveCurrentRecord
mCurrentRecord = mCurrentRecord - 1
ShowCurrentRecord
End If
txtID.SetFocus
End Sub
Private Sub cmdDelete_Click()
Dim DirResult
Dim TmpFileNum
Dim TmpPerson As PersonalInfo
Dim RecNum As Long
Dim TmpRecNum As Long
If MsgBox("Delete the current record?", vbYesNo + vbCritical, "Douglas Lads Club") = vbNo Then
txtID.SetFocus
Exit Sub
End If
If Dir("Data/addressbook.tmp") = "addressbook.tmpP" Then
Kill "Data/addressbook.tmp"
End If
TmpFileNum = FreeFile
Open "Data/addressbook.tmp" For Random As TmpFileNum Len = mRecordLen
RecNum = 1
TmpRecNum = 1
Do While RecNum < mLastRecord + 1
If RecNum <> mCurrentRecord Then
Get #mFileNum, RecNum, TmpPerson
Put #TmpFileNum, TmpRecNum, TmpPerson
TmpRecNum = TmpRecNum + 1
End If
RecNum = RecNum + 1
Loop
Close mFileNum
Kill "Data/addressbook.dat"
Close TmpFileNum
Name "Data/addressbook.tmp" As "Data/addressbook.dat"
mFileNum = FreeFile
Open "Data/addressbook.dat" For Random As mFileNum Len = mRecordLen
mLastRecord = mLastRecord - 1
If mLastRecord = 0 Then mLastRecord = 1
If mCurrentRecord > mLastRecord Then
mCurrentRecord = mLastRecord
End If
ShowCurrentRecord
txtID.SetFocus
End Sub
Private Sub cmdSearch_Click()
Dim NameToSearch As String
Dim Found As Integer
Dim RecNum As Long
Dim TmpPerson As PersonalInfo
NameToSearch = InputBox("Search for Member ID :", "Search Members")
If NameToSearch = "" Then
txtID.SetFocus
Exit Sub
End If
NameToSearch = UCase(NameToSearch)
Found = False
For RecNum = 1 To mLastRecord
Get #mFileNum, RecNum, TmpPerson
If NameToSearch = UCase(Trim(TmpPerson.MemberID)) Then
Found = True
Exit For
End If
Next
If Found = True Then
SaveCurrentRecord
mCurrentRecord = RecNum
ShowCurrentRecord
Else
MsgBox "The Member ID you entered could not be found!" & vbCrLf & vbCrLf & "Tip : Enter the correct Member Id Number to search!", vbInformation, "Douglas Lads Club"
End If
txtID.SetFocus
End Sub
Private Sub Form_Paint()
Shadow Me, txtID, 2, vbBlack
Shadow Me, txtName, 2, vbBlack
Shadow Me, txtAddress, 2, vbBlack
Shadow Me, txtPostal, 2, vbBlack
Shadow Me, txtHome, 2, vbBlack
Shadow Me, txtMobile, 2, vbBlack
End Sub
Private Sub Form_Unload(Cancel As Integer)
SaveCurrentRecord
End Sub
Private Sub cmdExit_Click()
SaveCurrentRecord
Unload Me
End Sub
Private Sub cmdNew_Click()
SaveCurrentRecord
mLastRecord = mLastRecord + 1
mPerson.MemberID = ""
mPerson.MembersName = ""
mPerson.MembersAddress = ""
mPerson.MembersPostalCode = ""
mPerson.MembersHomePhone = ""
mPerson.MembersMobileNumber = ""
Put #mFileNum, mLastRecord, mPerson
mCurrentRecord = mLastRecord
ShowCurrentRecord
txtID.SetFocus
End Sub
Private Sub cmdNext_Click()
If mCurrentRecord = mLastRecord Then
Beep
MsgBox "Its the last record !", vbExclamation, "Douglas Lads Club"
Else
SaveCurrentRecord
mCurrentRecord = mCurrentRecord + 1
ShowCurrentRecord
End If
txtID.SetFocus
End Sub
Private Sub Form_Load()
mRecordLen = Len(mPerson)
mFileNum = FreeFile
Open "Data/addressbook.dat" For Random As mFileNum Len = mRecordLen
On the assumption that you already know how to add the listview to your components tab...
To retaining existing code... place all textboxes relevant to mPerson in a picture box... make another picture box and place the listview control in this 2nd pic box... then add this in your Form_Load() event after call to ShowCurrentRecord.
Try to get a feel for the listview first. All other codes will have to be updated also... we will remove textbox ties to the data source bit by bit and redirect them to the listview.
Last edited by leinad31; Oct 7th, 2006 at 09:35 AM.
1) update listview items then update the entire file by downloading all listview info
2) update immediately the record in the file per listitem update
So which implementation would you prefer? Also in what order do you want the update? File first before listview or theother way around?
Either way you will need an interface to accept new values, this can be done with Picture1.Visible = True under a new command button cmdEdit. We will use the textboxes as data entry controls.
But before that, next and back will become obsolete so add these in your form load event
K made some changes to frmAddressBook... though the app doesn't have handling routines for zero records yet. I also included code for resorting the list based on clicked columns.
You will have problems with convergence (listview data matches textbox data) if the user edits data in textboxes when both are shown. To prevent that... In the last project, you could initially set the textboxes locked property to true, and unlock them only on cmdEdit.... When creating new records, set ListView1.Selected = nothing and refresh then go to textboxes (unlock same as in edit).... in the listview's itemclick event, call ShowCurrentRecord after updating mCurrentRecord to update textboxes, you navigate with listview so keep next and back buttons hidden.
Have to go to bed now... so sleepy i'm programming slow. Changes took more time than I expected.
Ciao!
Last edited by leinad31; Oct 7th, 2006 at 01:06 PM.