I'm currently designing a database for a "personal training company". I've got code working for things like closing forms, passwords and error messages. Now in my forms, for example the Client Form, I'm trying to use code for the "Next" and "Previous" record button instead of using the wizard. I've had help from teachers and peers but it's not working and I really need some help. Here is what I have got so far with their help:
Option Compare Database
Option Explicit
Dim rstClientDetails As DAO.Recordset
Private Sub Form_Load()
'create a connection with the current database
Call setDatabaseConnection
'create a set of film detail records
Set rstClientDetails = dbase.OpenRecordset("tblClient", dbOpenDynaset)
End Sub
Private Sub Form_Activate()
'everytime this form is active, refresh the current record details
Call displayCurrentRecord
End Sub
Private Function validRecord() As Boolean
'check if record pointer is at a valid record
'-1 is a flag value used to indicate an invalid
'position in a record set
'MsgBox rstMemberDetails.AbsolutePosition
If rstClientDetails.AbsolutePosition = -1 Then
validRecord = False
Else
validRecord = True
End If
End Function
Private Sub displayCurrentRecord()
'assign form text boxes to values from a record set
'need to check record pointer is pointing to a valid record in the set ...
If validRecord Then
txtClientID.Value = rstClientDetails("ClientID")
txtTitle.Value = rstClientDetails("Title")
txtFirstName.Value = rstClientDetails("FirstName")
txtSurname.Value = rstClientDetails("Surname")
txtDOB.Value = rstClientDetails("DOB")
txtAddress1.Value = rstClientDetails("Address1")
txtAddress2.Value = rstClientDetails("Address2")
txtCity.Value = rstClientDetails("City")
txtPostCode.Value = rstClientDetails("Postcode")
txtTel_No.Value = rstClientDetails("Tel_No")
End If
End Sub
Private Sub cmdNext_Click()
If Not rstClientDetails.EOF Then
rstClientDetails.MoveNext
End If
If Not rstClientDetails.EOF Then
Call displayCurrentRecord
Else
MsgBox "End of Record Set"
rstClientDetails.MoveLast
End If
End Sub
Private Sub cmdPrevious_Click()
'write your code here
If Not rstClientDetails.BOF Then
rstClientDetails.MovePrevious
End If
If Not rstClientDetails.BOF Then
Call displayCurrentRecord
Else
MsgBox "Start of record set - no more records "
rstClientDetails.MoveFirst
End If
End Sub
'This will close the Client Form
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
I would really appreciate the help guys, thanks
Option Compare Database
Option Explicit
Dim rstClientDetails As DAO.Recordset
Private Sub Form_Load()
'create a connection with the current database
Call setDatabaseConnection
'create a set of film detail records
Set rstClientDetails = dbase.OpenRecordset("tblClient", dbOpenDynaset)
End Sub
Private Sub Form_Activate()
'everytime this form is active, refresh the current record details
Call displayCurrentRecord
End Sub
Private Function validRecord() As Boolean
'check if record pointer is at a valid record
'-1 is a flag value used to indicate an invalid
'position in a record set
'MsgBox rstMemberDetails.AbsolutePosition
If rstClientDetails.AbsolutePosition = -1 Then
validRecord = False
Else
validRecord = True
End If
End Function
Private Sub displayCurrentRecord()
'assign form text boxes to values from a record set
'need to check record pointer is pointing to a valid record in the set ...
If validRecord Then
txtClientID.Value = rstClientDetails("ClientID")
txtTitle.Value = rstClientDetails("Title")
txtFirstName.Value = rstClientDetails("FirstName")
txtSurname.Value = rstClientDetails("Surname")
txtDOB.Value = rstClientDetails("DOB")
txtAddress1.Value = rstClientDetails("Address1")
txtAddress2.Value = rstClientDetails("Address2")
txtCity.Value = rstClientDetails("City")
txtPostCode.Value = rstClientDetails("Postcode")
txtTel_No.Value = rstClientDetails("Tel_No")
End If
End Sub
Private Sub cmdNext_Click()
If Not rstClientDetails.EOF Then
rstClientDetails.MoveNext
End If
If Not rstClientDetails.EOF Then
Call displayCurrentRecord
Else
MsgBox "End of Record Set"
rstClientDetails.MoveLast
End If
End Sub
Private Sub cmdPrevious_Click()
'write your code here
If Not rstClientDetails.BOF Then
rstClientDetails.MovePrevious
End If
If Not rstClientDetails.BOF Then
Call displayCurrentRecord
Else
MsgBox "Start of record set - no more records "
rstClientDetails.MoveFirst
End If
End Sub
'This will close the Client Form
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
I would really appreciate the help guys, thanks