Dmax in text field containing text and number value (2 Viewers)

Seph

Member
Local time
Today, 12:22
Joined
Jul 12, 2022
Messages
72
Good day everyone,

I have a sequential field called InvoiceNumber.

1669029735432.png

1669029748582.png

I'd like to use DMax to reference the highest value and then add a one to it. I have this setup in the On_Load Event on my Invoice New Form.

1669029851910.png


However, I'm getting the following error

1669029981700.png


Is this due to it referencing the I in the text field? is there a way to isolate the DMax function to the numeric value of the text field only?

Thanks!
 

Ranman256

Well-known member
Local time
Today, 06:22
Joined
Apr 9, 2015
Messages
4,337
Your field is a string. You can’t do math on text,
convert to number:

dim iNum as long
iNum = val(Dmax(...)) + 1
 

Eugene-LS

Registered User.
Local time
Today, 13:22
Joined
Dec 7, 2018
Messages
481
I'm getting the following error
Try:
Code:
Dim InvoiceNumber As Long
    
    InvoiceNumber = DMax("Val(Mid(InvoiceNumber, 2))", "InvoiceT") + 1
 

Minty

AWF VIP
Local time
Today, 11:22
Joined
Jul 26, 2013
Messages
10,371
The real answer here is to simply store a real number and display it using appropriate formatting.
Then you wouldn't need to jump through hoops to do the rest of the process.
 

ebs17

Well-known member
Local time
Today, 12:22
Joined
Feb 7, 2020
Messages
1,946
You have to solve self-created problems.

InvoiceNumber should be a number (Long) in the table. Then your calculation works simply and easily. You can use the format property of a control in forms/reports to display the desired format.

The property only affects the display, it does not change the value.
 

Seph

Member
Local time
Today, 12:22
Joined
Jul 12, 2022
Messages
72
Thank you everyone for your feedback.

I'm going to try setting it to a Number value and play with the format of the property in the Form. Will post result when I get it working.
 

Seph

Member
Local time
Today, 12:22
Joined
Jul 12, 2022
Messages
72
Ok, so it is working now.

The easiest solution is curtsey of @Ranman256 , @Minty and @ebs17.

1. Store the value in the table as a Number data type.
2. On the Form I used the following VBA code to find the largest number in the InvoiceNumber field and incremented it by 1:

Private Sub Form_Load()

InvoiceNumber = DMax("InvoiceNumber", "InvoiceT") + 1

End Sub

3. To get the desired look in my report, I changed the Format in the Property Sheet

1669036916296.png


1669037001814.png


Thanks again everyone.
 

Minty

AWF VIP
Local time
Today, 11:22
Joined
Jul 26, 2013
Messages
10,371
Glad you fixed it and your problem.
You will find that all sorts of things will be quicker and easier with a real number instead of something kludged together.
 

Users who are viewing this thread

Top Bottom