Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URGENT Questions - How to Put a Prefix on a DMax Number

Status
Not open for further replies.

quest4

Technical User
Aug 27, 2001
735
0
0
US
Good afternoon. I have been trying to figure this out fore a week now and nothing works. Not DMax, not recordsets with tables, nothing, all work partially. I have a subform and there are two field on it, ItemNumber and PartNumber. I am not sure this is doable or not, but I need to have groups in the subform like this:
1-1 .6875 hex brass
1-2 f-6
1-3 t189-3
When ever CTRL-b is pressed
2-1 .6875 rd brass
2-2 or-10
In other words when ever CTRL-b is press the prefix number increases by 1 and DMax restarts its count from 1 and both reset to 1 when a new record comes up. It does not have to be DMax I will try anything now. I have a 2:00PM presentation of this dbase to the senior staff. Right now the way it is working, it will probably be scrap and thrown out. I have tried everything I can here, so thank you very much to anyone who renders any assistance.
 
quest4,

Ok, My solution to your problem revoles around 2 functions. I assume that the itemnumber field in the subform is a string. With that, I wrote the functions to increase either the left number or right number.

Public Function IncreaseRightNumber(Optional itemnumber As String)
Dim lngValue As Long, strUpValue As String
On Error GoTo err_handler

If IsNull(itemnumber) Or itemnumber = "" Then
IncreaseRightNumber = "1-1"
Exit Function
End If

lngValue = CLng(Right(itemnumber, 1))
lngValue = lngValue + 1
strUpValue = CStr(lngValue)

IncreaseRightNumber = Left(itemnumber, 2) & strUpValue
err_handler:
If Err.Number > 1 Then
MsgBox Err.Description, , "Increase Right Number"
Exit Function
End If
End Function

Public Function IncreaseLeftNumber(Optional itemnumber As String)
Dim lngValue As Long, strUpValue As String
On Error GoTo err_handler

If IsNull(itemnumber) Or itemnumber = "" Then
IncreaseRightNumber = "1-1"
Exit Function
End If

lngValue = CLng(Left(itemnumber, 1))
lngValue = lngValue + 1
strUpValue = CStr(lngValue)

IncreaseLeftNumber = strUpValue & "-1"

err_handler:
If Err.Number > 1 Then
MsgBox Err.Description, , "Increase Left Number"
Exit Function
End If
End Function

You will notice that in order to call these functions, you will use them as follows.
When the subform is first open, call the function. Because the field is null or empty, the returm value will be "1-1". For every new record, call the IncreaseRightNumber function to increase the right digit. When you press Crtl-B, call the IncreaseLeftNumber function to increase the left digit and reset the right digit to 1.

I will leave it up to you to work them in where you need them. Hope this helps.

Rick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top