Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    Salty Mariner is offline Intermediate
    Windows 11 Access 2021
    Join Date
    Dec 2023
    Location
    Corpus Christi, TX
    Posts
    79
    Quote Originally Posted by June7 View Post
    Those two functions could be modified to one function. Are you familiar with how to build functions with arguments?



    If users don't need to see these calcs, textboxes can be not Visible. In fact, if these calcs are only necessary for further calcs, possibly don't even need textboxes. Call the function(s) from other function, use arguments.

    Should probably test for EOF not BOF.
    I am indeed familiar with building functions with arguments My Mercator Sailing Functions Take 4 arguments for Course and 5 arguments for distance. Those 4 textboxes actually feed those 4 arguments for Course and then I need those 4 arguments Plus the course to obtain the distance. While it may seem redundant the formulas that make it all work require it. The methodology of it all was lifted from "Bowditch - The American Practical Navigator". I just translated their formulas to VBA. As I said this was a proof of concept and I can now work on streamlining things and perhaps making it all more efficient. I don't know If I can make this ALL work in code as I think I need a textbox or some control from which to call the code that is specific to that record. I'll be continuing to play with this and refine it.

    This whole Navigation project started for me over 20 years ago. First in Excel formulas, Then to Excel with VBA functions, and then I modified my functions for Access. 20 years ago I had a voyage planner working in Excel. I wanted to try my hand at making this work in Access.

  2. #17
    Salty Mariner is offline Intermediate
    Windows 11 Access 2021
    Join Date
    Dec 2023
    Location
    Corpus Christi, TX
    Posts
    79
    Hello everyone.

    I thought I would update people here who might be following this thread. With a good deal of searching I found some module based code elsewhere written 13 years ago by a forum user named MajP. Essentially what it does is if you have a sort field Like my form does which is essentially what my LegNo field is the code will swap the value of the current sort number with that of the previous one and then requery and do a FindRecord. It does the reverse to perform a move down. This was a lifesaver for me as I might have never come up with this on my own. Examining the code is a great learning experience as well. Form the little bit I have played with it it seems to work. I need to enter some more data and see if I can find any bugs which I assume would occur when reaching BOF or EOF.

    Here is the code:

    Code:
    Public Sub SetInitialSort(SortField, frm)
      Dim rs As DAO.Recordset
      Set rs = frm.Recordset
      Do While Not rs.EOF
        rs.Edit
        rs.Fields(SortField) = rs.AbsolutePosition + 1
        rs.Update
        rs.MoveNext
      Loop
      rs.MoveFirst
    End Sub
    
    Public Sub moveSortUp(SortField, frm As Access.Form)
      Dim rsClone As DAO.Recordset
      Dim lngNewSort As Long
      Dim lngOldSort As Long
      Set rsClone = frm.RecordsetClone
      rsClone.AbsolutePosition = frm.Recordset.AbsolutePosition
      If Not (IsNull(rsClone.Fields(SortField)) Or rsClone.AbsolutePosition <= 0) Then
        lngOldSort = rsClone.Fields(SortField)
        lngNewSort = lngOldSort - 1
        rsClone.Edit
        rsClone.Fields(SortField) = lngNewSort
        rsClone.Update
        rsClone.MovePrevious
        rsClone.Edit
        rsClone.Fields(SortField) = lngOldSort
        rsClone.Update
      frm.Requery
      frm.Recordset.FindFirst SortField & " = " & lngNewSort
      End If
    End Sub
    
    Public Sub MoveSortDown(SortField, frm As Access.Form)
      Dim rsClone As DAO.Recordset
      Dim lngNewSort As Long
      Dim lngOldSort As Long
      Set rsClone = frm.RecordsetClone
      rsClone.AbsolutePosition = frm.Recordset.AbsolutePosition
      If Not (IsNull(rsClone.Fields(SortField)) Or rsClone.AbsolutePosition >= rsClone.RecordCount - 1) Then
        lngOldSort = rsClone.Fields(SortField)
        lngNewSort = lngOldSort + 1
        rsClone.Edit
        rsClone.Fields(SortField) = lngNewSort
        rsClone.Update
        rsClone.MoveNext
        rsClone.Edit
        rsClone.Fields(SortField) = lngOldSort
        rsClone.Update
      frm.Requery
      frm.Recordset.FindFirst SortField & " = " & lngNewSort
      End If
    End Sub

  3. #18
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,976
    Yes, he writes good classes as well. You should Google his FAYT classes.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Get ID of previous record in a Continuous form
    By jschneiter in forum Access
    Replies: 6
    Last Post: 10-17-2020, 08:31 AM
  2. Replies: 9
    Last Post: 01-30-2020, 10:40 PM
  3. iif referring to previous record
    By =Roman in forum Queries
    Replies: 3
    Last Post: 06-23-2016, 04:51 AM
  4. Replies: 10
    Last Post: 10-23-2012, 12:08 PM
  5. Replies: 2
    Last Post: 11-26-2010, 04:20 AM

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