Search code examples
.netdatabasevb.netms-accessautonumber

Cutting off the 0's at the front of a record


This may be a basic question but I have no idea on how to word it in Google.

Basically, I have an Access database with Primary keys that are structured with this format ("02"000).

When I try to paste the number, it ignores the "02" and goes straight to 000.

For example, here is the code;

PeriodRoomID.Name = ("R" & ds.Tables("sqlSpecRoomRequest").Rows(i).Item(1))

What PeriodRoomID.Name should be is R02001. What PeriodRoomID.Name comes up as is R1.

It ignores the "02" and ignores the 0s. This makes sense mathematically but it is not what I want. I need a way to get the exact output and not some simplified version.

The query;

SELECT SpecialSoftware.SpecSoftID, SpecialSoftware.RoomID, SpecialSoftwareNames.Description, Rooms.Capacity
FROM SpecialSoftware, SpecialSoftwareNames, Rooms

Solution

  • You could just format the number inside your app:

    Dim roomID As String = ds.Tables("sqlSpecRoomRequest").Rows(i).Item(1)
    PeriodRoomID.Name = "R02" & roomID.PadLeft(3, "0"c)