Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I suggest you create a function. You would need to know the incoming measurement unit,
    then an expression(vba code) to calculate the target unit.(inches)

    Using a number found via Google

    1 mm = 0.0393701 inches

    sample:

    Code:
    Function MMToInches(NumMM As Double) As Double
    
    Dim ConvFactor As Double
    ConvFactor = 0.0393701 ' 1 mm = 0.0393701 inches
    MMToInches = NumMM * ConvFactor
    
    End Function

    sample usage: if height is in mm



    Select MMtoInches(Height) as HgtInches from tblExport

  2. #17
    natonstan is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Posts
    37
    Quote Originally Posted by orange View Post
    I suggest you create a function. You would need to know the incoming measurement unit,
    then an expression(vba code) to calculate the target unit.(inches)

    Using a number found via Google

    1 mm = 0.0393701 inches

    sample:

    Code:
    Function MMToInches(NumMM As Double) As Double
    
    Dim ConvFactor As Double
    ConvFactor = 0.0393701 ' 1 mm = 0.0393701 inches
    MMToInches = NumMM * ConvFactor
    
    End Function

    sample usage: if height is in mm

    Select MMtoInches(Height) as HgtInches from tblExport
    I was trying to do this using SQL, I came up with this but for some reason it just isn't working, I keep getting syntax errors, here's the example code:

    SELECT [Part Number], ...,
    CAST(CASE WHEN is_in_inches = 1 THEN Dimensions ELSE Dimensions / 25.4 END AS decimal(9, 2)) AS Dimensions, CAST(CASE WHEN is_in_inches = 1 THEN Height ELSE Height / 25.4 END AS decimal(9, 2)) AS Height,
    ...
    FROM
    CROSS APPLY (
    SELECT CASE WHEN Unit IN ('In', 'Inch') THEN 1 ELSE 0 END AS is_in_inches
    ) AS ca1

    Here's all of the fields in my external data file:

    Part Number, Manufacturer Number, Dimensions, Height, Length, Width, Unit

    Now Dimensions is simply blank right now, Height, Length, Width all have numbers, the Unit field is what indicates whether it is in 'in' or 'mm'

  3. #18
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    just use the example provided 3 times in a query

  4. #19
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I reread your post and see you want measurements in Units of feet.
    Below is a sample function, a test routine and sample results.

    CASE is not an acceptable part of Access SQL.


    Code:
    Function UnitsToFeet(NumUnits As Double, Unit As String) As Double
    '
    '
        Dim ConvFactor As Double: ConvFactor = 0
        Select Case Unit
        Case "MM", "mm.", "millimeter"
            ConvFactor = 0.00328084   ' 1 mm = 0.0.00328084 feet
        Case "cm", "cm.", "centimeter"
            ConvFactor = 0.0328084 ' 1 cm = 0328084 feet
        Case "m", "meter", "metre"
            ConvFactor = 0.328084  '1 m = 0.328084
        Case "in", "in.", "inch", "inches"
            ConvFactor = 0.083333336 '1 Inch = 0.083333336 feet.
        Case "ft", "ft.", "feet", "foot"
            ConvFactor = 1
        End Select
        UnitsToFeet = NumUnits * ConvFactor
    
    
    End Function
    Sample test routine:
    Code:
    Sub testcnv()
        Dim testValues(3) As Double
        Dim i As Integer, j As Integer
        Dim jUnit(3) As String
    
        jUnit(0) = "mm"
        jUnit(1) = "inch"
        jUnit(2) = "cm"
        jUnit(3) = "ft"
    
        testValues(0) = 1
        testValues(1) = 23.25
        testValues(2) = 800.9876
        testValues(3) = 0.5
        For j = 0 To 3
            For i = 0 To UBound(testValues)
                Debug.Print testValues(i) & " " & jUnit(j) & "  equals  " & UnitsToFeet(testValues(i), jUnit(j)) & " feet"
            Next i
            Debug.Print vbCrLf
        Next j
    End Sub
    Results of test:
    Code:
    1 mm  equals  0.00328084 feet
    23.25 mm  equals  0.07627953 feet
    800.9876 mm  equals  2.627912157584 feet
    0.5 mm  equals  0.00164042 feet
    
    
    1 inch  equals  0.083333336 feet
    23.25 inch  equals  1.937500062 feet
    800.9876 inch  equals  66.7489688026336 feet
    0.5 inch  equals  0.041666668 feet
    
    
    1 cm  equals  0.0328084 feet
    23.25 cm  equals  0.7627953 feet
    800.9876 cm  equals  26.27912157584 feet
    0.5 cm  equals  0.0164042 feet
    
    
    1 ft  equals  1 feet
    23.25 ft  equals  23.25 feet
    800.9876 ft  equals  800.9876 feet
    0.5 ft  equals  0.5 feet

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

Similar Threads

  1. Replies: 3
    Last Post: 08-02-2015, 12:42 AM
  2. Converting Excel Formula to Access Query Format
    By Guy Winfield in forum Queries
    Replies: 2
    Last Post: 05-11-2015, 06:21 AM
  3. Replies: 1
    Last Post: 10-05-2013, 04:56 PM
  4. Replies: 1
    Last Post: 04-24-2013, 12:12 PM
  5. converting mdb to accdb format
    By crowegreg in forum Access
    Replies: 1
    Last Post: 05-31-2011, 10:34 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