Results 1 to 5 of 5
  1. #1
    beaurou is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    16

    Assign variable

    I have a table that looks like this, What I want to achieve is to assign 4 variables X1, X2, Y1 and Y2.

    Let say a user input -12 for X, so i need X1=-15, X2=-11, Y1=-100 and Y2=-60 or for user input 10 the variable will be X1=8.2, X2=18.9, Y1=25 and Y2=60



    Basicaly I need to use the value of the record before and the record after from the user request
    XY_Data_Point_Number X Y
    1 -15 -100
    2 -11 -60
    3 -5.5 -23
    4 -3.6 -10
    5 0 0
    6 1.6 4
    7 2.3 10
    8 8.2 25
    9 18.9 60
    10 31 100

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Could use domain aggregate expressions:

    x1 = DMax("X", "tablename", "X<" & [userXinput])
    x2 = DMin("X", "tablename", "X>" & [userXinput])

    DP1 = DLookup("XY_Data_Point_Number", "tablename", "X=" & x1)
    DP2 = DLookup("XY_Data_Point_Number", "tablename", "X=" & x2)

    y1 = DLookup("Y", "tablename", "XY_Data_Point_Number=" & DP1)
    y2 = DLookup("Y", "tablename", "XY_Data_Point_Number=" & DP2)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    If you use a query, the fields are the variables.

  4. #4
    beaurou is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    16
    June7

    I insert your code in mine and I receive always an error, I think I did point to the srtSQL

    Private Sub CalculatePLA()
    Dim LoSchedName As String 'Schedule name for lookup
    Dim HiSchedName As String 'Schedule name for high temperature
    Dim LowTemp As Single 'Low Temp value
    Dim HighTemp As Single 'High Temp value
    Dim PLATC As Single 'PLA temp corrected
    Dim Orderknots As Variant 'Order Knots user input
    Dim PPD As Single 'Calculated PPD
    Dim strSQL As String 'SQL string
    Dim PLA As Single 'Calculated PLA
    Dim PLAfound As Boolean 'PLA data exist
    Dim x1 As Single
    Dim x2 As Single
    Dim y1 As Single
    Dim y2 As Single
    Dim DP1 As Single
    Dim DP2 As Single

    'Check if Order Knots is numeric
    If (Not IsNumeric(TxtOrderKnots.Value)) Then
    'Not numeric so display message
    MsgBox "Order Knots must be a numeric value", vbOKOnly, "Input values"
    'Set focus to order knots and clear out value
    TxtOrderKnots.SetFocus
    TxtOrderKnots.Text = ""
    'Exit from routine
    Exit Sub
    End If

    'Check if CIT is numeric
    If (Not IsNumeric(TxtCIT.Value)) Then
    'Not numeric so display message
    MsgBox "CIT must be a numeric value", vbOKOnly, "Input values"
    'Set focus to CIT and clear out value
    TxtCIT.SetFocus
    TxtCIT.Text = ""
    'Exit from routine
    Exit Sub
    End If
    'Order Knots user input

    Orderknots = TxtOrderKnots.Value

    strSQL = "SELECT [1335_Schedule XY Data].[XY_Data_Point_Number], [1335_Schedule XY Data].[X], [1335_Schedule XY Data].[Y] " & _
    "FROM [1335_Schedule Information]INNER JOIN [1335_Schedule XY Data]" & _
    "ON [1335_Schedule Information].[Table_ID] = [1335_Schedule XY Data].[Table_ID] " & _
    "WHERE [1335_Schedule Information].[Schedule_Name]='ship_speed_ppd';"

    x1 = DMin("X", "strSQL", "X<" & [Orderknots])
    x2 = DMin("X", "strSQL", "X>" & [Orderknots])

    DP1 = DLookup("XY_Data_Point_Number", "1335_Schedule XY Data", "X=" & x1)
    DP2 = DLookup("XY_Data_Point_Number", "1335_Schedule XY Data", "X=" & x2)

    y1 = DLookup("Y", "1335_Schedule XY Data", "XY_Data_Point_Number=" & DP1)
    y2 = DLookup("Y", "1335_Schedule XY Data", "XY_Data_Point_Number=" & DP2)
    PPD = ((y1 - y2) / (x1 - x2)) * Orderknots + (-((y1 - y2) / (x1 - x2)) + x1 + y1)

    lblPPD.Value = Format(PPD, ".0")
    End Sub

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Can't use an SQL string in domain aggregate function. You are mixing methods. Use one or the other. Even if this were possible, the strSQL variable would not be within quote marks. Variables are never within quotes. Anything within quotes is considered literal text.

    Use SQL string to open a recordset
    The SQL string needs spaces so things don't run together. One in front of INNER and one at the end of that line.
    "FROM [1335_Schedule Information] INNER JOIN [1335_Schedule XY Data] " & _

    OR

    Use domain aggregates
    Instead of strSQL, refer to an Access table or query object.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 8
    Last Post: 08-17-2023, 02:33 AM
  2. Assign value to variable on other form
    By tylerg11 in forum Access
    Replies: 3
    Last Post: 08-20-2013, 07:48 AM
  3. Replies: 1
    Last Post: 04-25-2013, 02:52 PM
  4. Replies: 0
    Last Post: 08-10-2011, 11:59 AM
  5. Assign and call variable from table
    By smikkelsen in forum Access
    Replies: 7
    Last Post: 04-01-2010, 09:38 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