|
-
Feb 19th, 2009, 04:35 AM
#1
Thread Starter
Lively Member
Move previous
Private Sub Command4_Click()
If rs.BOF = False Then
rs.MovePrevious
If rs.BOF = True Then
rs.MoveFirst
End If
Else
If rs.EOF Then
Else
rs.MoveFirst
End If
End If
End Sub
i am using the above command to move to the previous record.. but its not working.. .
any ideas
-
Feb 19th, 2009, 05:13 AM
#2
Re: Move previous
To cheat:
Code:
On Error Resume Next
rs.MovePrevious
If Err Then MsgBox "No previous record"
On Error Goto 0
-
Feb 19th, 2009, 08:00 AM
#3
Frenzied Member
Re: Move previous
see if this helps..
Code:
If rS.EOF Or rS.BOF Then
rS.MoveFirst
Else
rS.MoveNext
End If
pls use CODE tags
-
Feb 19th, 2009, 08:05 AM
#4
Re: Move previous
Thread moved to Database Development forum (the "VB6" forum is meant for questions which don't fit in more specific forums)
 Originally Posted by joevb84
i am using the above command to move to the previous record.. but its not working.. .
I'm willing to bet that it is working (at least in some circumstances), and that you could tell that be debugging, but that there are no visible changes - because you are just moving to a different record, you are not actually doing anything with it (such as putting the data into textboxes etc).
If you are using the ADO Tutorial from our FAQs (link in my signature), you need to call FillFields to show the data. I'd recommend taking a look at the MovePrevious code there, as it has been tested to work in all cases (such as reaching BOF when you move, etc).
-
Feb 19th, 2009, 09:51 PM
#5
Thread Starter
Lively Member
Re: Move previous
I went through the tutorial and found understood some what.. but this is the problem
Private Sub Command4_Click()
'check if there are records to move
If Not (rs.BOF = True And rs.EOF = True) Then
rs.MovePrevious 'move previous record
'if we did not reach the first record then show it
If Not rs.BOF Then
FillFields 'fill the controls
Else
'if we are not on the last record then MoveFirst
If Not rs.EOF Then
rs.MoveFirst 'go to the first record
End If
MsgBox "First record reached! ", vbExclamation, "Status"
End If
Else
MsgBox "No record is existing, Move Previous not allowed! ", vbExclamation, "No Record"
End If
End Sub
when i click the button it is sayin first record reached but all the fields are empty
and for the next click
check if there are records to move
If Not (rs.BOF = True And rs.EOF = True) Then
rs.MoveNext 'move to next record
'if we did not reach the last record then show it
If Not rs.EOF Then
FillFields 'fill the controls
Else
rs.MoveLast 'go to the last record
MsgBox "Last record reached! ", vbExclamation, "Status"
End If
Else
MsgBox "No record is existing, Move Next not allowed! ", vbExclamation, "No Record"
End If
End Sub
it says "error 94" Invalid use of null...
I have no idea what to do
Last edited by joevb84; Feb 20th, 2009 at 12:16 AM.
-
Feb 20th, 2009, 06:32 AM
#6
Frenzied Member
Re: Move previous
joe I, like many others have this problem. I keep losing the flow of program in an un-indented code snippet. So copy out your code into your VB indent the same, and post it with CODE tags 
pls also post your code (of course indented+CODE tags) of FillFields
-
Feb 20th, 2009, 09:27 AM
#7
Re: Move previous
To use Code tags, either use the Code/VBCode buttons in the post editor screen (or at the top of the Quick Reply box), or by putting them in manually, like this:
[code] code here [/code]
 Originally Posted by joevb84
when i click the button it is sayin first record reached but all the fields are empty
Were they empty before?
If so, they should still be empty - as you haven't actually moved to another record (because there wasn't a previous one to go to).
it says "error 94" Invalid use of null...
You are withholding essential information... While the error message (and number) are very important, the line of code it occurred on (which is highlighted when the error is shown) is needed too.
VBFnewcomer is on the right track, FillFields is almost certainly where it is occurring.
-
Feb 20th, 2009, 10:42 PM
#8
Thread Starter
Lively Member
Re: Move previous
]Hi guys
I had empty records being called. so now i made the added nz and "" & to each of the variables in the fill fields
Code:
Public Sub FillFields()
If Not (rs.BOF = True Or rs.EOF = True) Then 'Checks if we are at the first or last record. This is use a lot.
Hosp_num.Text = "" & rs.Fields("Hosp_num")
Pat_nam.Text = "" & rs.Fields("Pat_nam") 'setting field2 = whatever is typed in text1
Pat_age.Text = "" & rs.Fields("Pat_age")
Fath_hus_nam.Text = "" & rs.Fields("fath_hus_nam")
Dor.Value = Nz(rs.Fields("dor"))
Pat_sex = "" & rs.Fields("Pat_sex")
Pat_occ.Text = "" & rs.Fields("Pat_occ")
Pat_add.Text = "" & rs.Fields("Pat_add")
Pat_blood = "" & rs.Fields("Pat_blood")
Pat_aller.Text = "" & rs.Fields("Pat_Aller")
Else
'reset the textbox and combobox if there are no more records
Hosp_num.Text = ""
Pat_nam.Text = ""
Pat_age.Text = ""
Fath_hus_nam.Text = ""
Dor.Value = Now()
Pat_sex = ""
Pat_add.Text = ""
End If
End Sub
Public Function Nz(pvar As Variant, Optional pvarReplace As Variant = 0) As Variant
If IsNull(pvar) Then Nz = pvarReplace Else Nz = pvar
End Function
The new problem here is with the date field. Rest two problems kind of got sorted after adding the Nz and ""&. But the problem is sometimes my date field is empty. therefore it gives me an error Any idea how to over come this
Last edited by joevb84; Feb 21st, 2009 at 12:53 AM.
-
Feb 20th, 2009, 11:57 PM
#9
Re: Move previous
You can check if a certain field is a valid date.
Code:
If IsDate(rs.Fields("dor")) Then
Dor.Value = rs.Fields("dor")
End If
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
|