Results 1 to 4 of 4
  1. #1
    Velt is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2022
    Posts
    1

    Mac Address Formatting in MS Access

    Hi Everyone, New to MS Access. Had a question regarding formatting of a MAC Address in one of my Access forms. There is a field I have set up using an input mask aa:aa:aa:aa:aa:aa;;a where users can manually enter a 48 bit hexidecimal address. e.x 11:44:5E:33:53:AF.




    However sometimes there are missing values that occur in this data entry e.x 0:A:B:11:22:C (happens from time to time) but I would like be able to automatically fill the missing values with leading zeros to be like 00:0A:0B:11:22:0C.
    I realize that this may not be possible through just MS Access Input masks, but all of the VBA codes and after updates code building I have been looking at so far have not lead me to the desired format.


    Thanks for your time and appreciate any help in this!


    I tried Format(fieldname, "00000000") code, but it just fills from the left-hand side instead of between the colons. e.x 00:00:0A:B1:12:2C instead of the desired 00:0A:0B:11:22:0C.

  2. #2
    Join Date
    Apr 2017
    Posts
    1,792
    Write an UDF, which
    1. Processes the string (SourceString), searching for 1st occurrence of character ":" (position x), and calculates 1st hexadecimal into ResultString as Right("00" & MID(SourceString, 1, x-1),2) & ":"
    2. Recalculates SourceString as MID(SourceString, x+1, 250)
    3. Repeats 1.-2. until no ":" is found, every time adding next 2-character hexadecimal and ":" to ResultString;
    4. Adds Right("00" & SourceString,2) to ResultString;
    5. Returns ResultString.

    Use the UDF to update original data (e.g. in Update Query, or in BeforeUpdate event of form control).

    NB! The function described above can't cope with cases, where some ":" was omitted, or where more than 2 characters were in a section of original hexadecimal!

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    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

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    An alternative to Mid() is Split().

    Code:
    Function FixMac(strS As String)
    Dim strMac As String, x As Integer
    For x = 0 To 5
        strMac = strMac & Right("00" & Split(strS, ":")(x), 2) & ":"
    Next
    FixMac = Left(strMac, 17)
    End Function
    Assumes there will always be 6 parts separated by colon.

    I have used textbox AfterUpdate event for this sort of data fix.

    Could change data entry so users are not typing this string all into one textbox.
    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: 4
    Last Post: 05-12-2021, 06:20 AM
  2. Replies: 4
    Last Post: 01-06-2018, 03:26 PM
  3. Replies: 7
    Last Post: 06-27-2016, 12:28 PM
  4. Replies: 2
    Last Post: 08-22-2013, 12:02 AM
  5. Input Mask for an IP Address and Mack Address
    By baksg1995 in forum Access
    Replies: 18
    Last Post: 06-23-2009, 12:33 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