Results 1 to 9 of 9
  1. #1
    fabiobarreto10 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    169

    doubt with MoveLast


    Lords of this fantastic forum, I have this code:

    Dim DataAnterior As Date
    Dim Db As Database, Rs As Recordset, Sql As String
    Set Db = CurrentDb
    Set Rs = Db.OpenRecordset("SELECT DataRealizada FROM TblPassosStatus WHERE CodProduto =" & CodProduto)


    DataAnterior = Rs.Fields(0)


    Using rs.Fields (0) I get the first column value.
    How to use MoveLast for the last column value even if
    this value is null?


    Thank you.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You're only selecting one column, so you wouldn't get any others. If you select more, you can get them with

    rs.Fields(x)

    where x is the column you want (starting at 0), or

    rs!FieldName

    which is my preference, as it's self-documenting.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Oh, and MoveLast is for moving to the last record, not the last field in a record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    fabiobarreto10 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    169
    Yes, I'm getting the first column value, how do I get the last value, using the move.last.

    Yes, I want to move to the last record of the column and get value.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If you want the last record

    rs.MoveLast
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    fabiobarreto10 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    169
    Thanks, now I just like when the value is null. For example I have this code:

    Set Rs = Db.OpenRecordset("SELECT DataRealizada,DataReprogramada, DataProgramada FROM TblPassosStatus WHERE CodProduto =" & CodProduto)
    Rs.MoveLast



    DateRealizada = Rs.Fields(0)

    DateReprogramada = Rs.Fields(1)

    DateProgramada = Rs.Fields(2)

    If IsNull(Me.[Passo]) Then Exit Sub
    If holstr = "" Then make_hols "c:\BD\FERIADO.txt", "1/1/" & Year(Now())

    If DateRealizada <> "" Then
    NewUpDate_Core Me.Passo, DateRealizada
    Else
    If DateReprogramada <> "" Then
    NewUpDate_Core Me.Passo, DateReprogramada
    Else
    If DateProgramada <> "" Then
    NewUpDate_Core Me.Passo, DateProgramada
    Else
    Exit Sub

    End If
    End If
    End If

    one of the three fields have a value, but shows an error message when a field has the null value. You can declare a variable as variant and if the value is not null do a conversion to Date?

    Thank you.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can just declare them as Variant; they will accept the date when it's there. There's no need to change how it was declared.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    fabiobarreto10 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    169
    It worked. Thank pbaldy.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA code syntac doubt "Before Insert"
    By ramindya in forum Programming
    Replies: 1
    Last Post: 02-12-2012, 07:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums