Question

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
Was it helpful?

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)

OTHER TIPS

I suggest that you have an autonumber field with a format set to "02"000. All the format does is display the data to an Access user in that format. The field does not contain 02001, it contains 1. If you wish to recreate the format, you will have to do so in your application. Updating the autonumber to n will show as n in ADO and ODBC, but as 0200n in various places in Access - a format is not even relevant to queries in Access. I do not believe a format in a table is a good idea.

Can you access to the "02" only? You wrote your query ignores "02", so it looks you need to have a single query for this piece of information.
I'm no expert in vb or access, but it looks like you can use a quick'n'dirty solution: You wrote, your keys have the form "02"000. I would take out each number by itself, check the number of digits, convert it to string and fill all leading zeros that are missing, because you know the maximum number of digits.

Referring to what overall comments show: Filling dynamically leading zeros and referring to your table by name to decide by if-clause if your room-ID starts with R01 or R02.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top