Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Formatting IP addresses in Access

76 views
Skip to first unread message

Y. Park

unread,
Mar 17, 1998, 3:00:00 AM3/17/98
to

Does anyone know how to format IP addresses in Access so that they sort
correctly in the tables? For now, I just use an input mask that makes an
IP look like this: 128.095.022.007. Of course, this format works fine
when I sort the IPs in ascending or descending order but, it would be nice
to get rid of those extra zeros and still sort correctly.

Thanks,
Yong Park


Brendan Reynolds

unread,
Mar 18, 1998, 3:00:00 AM3/18/98
to

I store IP addresses as 4 separate numeric fields, IPA, IPB, IPC and IPD.
Then I combine them using IP = [IPA] & "." & [IPB] & "." & [IPC] & "." &
[IPD]. For sorting, I use the numeric fields - ORDER BY [IPA], [IPB], [IPC],
[IPD]. Because the fields are numeric, they sort correctly regardless of the
number of digits.

I have to store the four parts of the address separately anyway, because I'm
dealing with a class C licence, so if IPD reaches 255 I need to restart IPD
and increment IPC. If you're not doing something like this, then using four
separate fields just for sorting purposes would be a pain. Perhaps someone
else has a better solution?

Brendan Reynolds

Y. Park wrote in message ...

Trevor Best

unread,
Mar 19, 1998, 3:00:00 AM3/19/98
to

On Tue, 17 Mar 1998 19:58:01 -0800 in comp.databases.ms-access, "Y. Park"
<yon...@u.washington.edu> wrote:
>Does anyone know how to format IP addresses in Access so that they sort
>correctly in the tables? For now, I just use an input mask that makes an
>IP look like this: 128.095.022.007. Of course, this format works fine
>when I sort the IPs in ascending or descending order but, it would be nice
>to get rid of those extra zeros and still sort correctly.

You could try storing the fragments in 4 fields or use a function for the
output that strips the zeros.

\|||/
/ \
C o o D
-----------------ooO--u--Ooo-------------------------------
To reply my mail, replace the "nospam" in my address with "trevor",
this was put on in defence of the spam robots that roam usenet.
But please DONT cc me in on posts, I read this group as well.
MS Access FAQ now available on my site below.
http://www.trevor.easynet.co.uk/

Apathy Error: Don't bother striking any key.

0 new messages