|
-
Mar 30th, 2006, 04:51 AM
#1
Thread Starter
Lively Member
[RESOLVED] How to use IF NOT
Can anyone tell how to use the If Not so I don't have to use an exit sub to get out of the procedure
This works but I want to remove the exit sub
VB Code:
Public Sub FillLabels()
If Not (objrec.BOF = True) Or (objrec.EOF = True) Then
Exit Sub
End If
txtJobDescription = objrec.Fields("Job_Description").Value & " "
txtSubTotal.Text = Format$(objrec.Fields("Sub_Total").Value & " ", "Currency")
lblAddVAT = Format$(objrec.Fields("VAT").Value & " ", "Currency")
lblNewTotal = Format$(objrec.Fields("Total").Value & " ", "Currency")
End Sub
here is the code for the navigation
VB Code:
Public Sub Forward()
'If the recordset is not at the end of file....
If objrec.EOF = False Then
'....Move to the next record
objrec.MoveNext
'Call the Select_Case procedure to refill the labels with the next record
Select_Case
If objrec.EOF Then
'This will prevent the user from moving to
'the EOF Marker if he or she is on the last
'record.
objrec.MoveLast
End If
Else
If objrec.BOF Then
Exit Sub
Else
objrec.MoveNext
End If
End If
End Sub
I have a forward and back navigation buttons on my toolbar and use it to move forward and back records. I have tried using IF NOT around the booleans but When it reaches the last record it will crash saying 'Either BOF or EOF is True.......'
I want to be able to remove the Exit Sub becuase I have been told it's lazy programming to exit a sub routine
-
Mar 30th, 2006, 04:56 AM
#2
Re: How to use IF NOT
Pure logic... simply reverse the process 
VB Code:
Public Sub FillLabels()
If (objrec.BOF = True) Or (objrec.EOF = True) Then
txtJobDescription = objrec.Fields("Job_Description").Value & " "
txtSubTotal.Text = Format$(objrec.Fields("Sub_Total").Value & " ", "Currency")
lblAddVAT = Format$(objrec.Fields("VAT").Value & " ", "Currency")
lblNewTotal = Format$(objrec.Fields("Total").Value & " ", "Currency")
End If
End Sub
VB Code:
Public Sub Forward()
'If the recordset is not at the end of file....
If objrec.EOF = False Then
'....Move to the next record
objrec.MoveNext
'Call the Select_Case procedure to refill the labels with the next record
Select_Case
If objrec.EOF Then
'This will prevent the user from moving to
'the EOF Marker if he or she is on the last
'record.
objrec.MoveLast
End If
Else
If Not objrec.BOF Then
objrec.MoveNext
End If
End If
End Sub
In the second one, you are exiting the sub anyway when the If's finish. So you don't need Exit Sub.
-
Mar 30th, 2006, 05:12 AM
#3
Re: How to use IF NOT
you can use the not like this
VB Code:
Public Sub FillLabels()
If Not (objrec.BOF = True Or objrec.EOF = True) Then
txtJobDescription = objrec.Fields("Job_Description").Value & " "
txtSubTotal.Text = Format$(objrec.Fields("Sub_Total").Value & " ", "Currency")
lblAddVAT = Format$(objrec.Fields("VAT").Value & " ", "Currency")
lblNewTotal = Format$(objrec.Fields("Total").Value & " ", "Currency")
End If
End Sub
grouping the conditions is more important
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Mar 30th, 2006, 05:28 AM
#4
Thread Starter
Lively Member
Re: How to use IF NOT
Many thanks to both of you for helping me out woth this problem.
The problem is now fixed
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|