Results 1 to 9 of 9

Thread: Move previous

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    72

    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

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Move previous

    To cheat:
    Code:
    On Error Resume Next
    rs.MovePrevious
    If Err Then MsgBox "No previous record"
    On Error Goto 0
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  3. #3
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Cool 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

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Move previous

    Thread moved to Database Development forum (the "VB6" forum is meant for questions which don't fit in more specific forums)
    Quote 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).

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    72

    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.

  6. #6
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    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

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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]
    Quote 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.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    72

    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.

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    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
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width