Default value of text box

npa3000

Member
Local time
Today, 19:16
Joined
Apr 16, 2021
Messages
36
Good evening, I am trying to put the specific part of the code in the default value field of a text box but I get the following error.
Code:
= DMax("LOADING_ID", "LOADINGS", "ORDER_ID=" & Forms![LOADINGS]![ORDER_ID] & "") + 1

1640968579977.png


What can I fix?

Thanks!
 
Are you trying to generate the next value for Loading_ID within Order_ID? If no value for Loading_ID exists for the value of Order_ID, the dMax() returns null which would be your problem. So:
Code:
= Nz(DMax("LOADING_ID", "LOADINGS", "ORDER_ID=" & Forms![LOADINGS]![ORDER_ID] & ""),0) + 1

HOWEVER, this is the wrong place to generate this number. You are generating it way too early and the field is unbound so you actually need to do this as the LAST statement of the Form's BeforeUpdate event. Then It would be:
Code:
Me.Loading_ID = Nz(DMax("LOADING_ID", "LOADINGS", "ORDER_ID=" & Forms![LOADINGS]![ORDER_ID] & ""),0) + 1

PS, all caps for your code went out with COBOL in the 90's.
 
Are you trying to generate the next value for Loading_ID within Order_ID? If no value for Loading_ID exists for the value of Order_ID, the dMax() returns null which would be your problem. So:
Code:
= Nz(DMax("LOADING_ID", "LOADINGS", "ORDER_ID=" & Forms![LOADINGS]![ORDER_ID] & ""),0) + 1

HOWEVER, this is the wrong place to generate this number. You are generating it way too early and the field is unbound so you actually need to do this as the LAST statement of the Form's BeforeUpdate event. Then It would be:
Code:
Me.Loading_ID = Nz(DMax("LOADING_ID", "LOADINGS", "ORDER_ID=" & Forms![LOADINGS]![ORDER_ID] & ""),0) + 1

PS, all caps for your code went out with COBOL in the 90's.
I still get the same message. Does it need some special quotations in the criteria area?

I just want to get the next loading id in a form, so i want to put this command to the property "Default value"

I tried your suggestion but it doesn't work for all the records. In this point i have to say that i work in a continious form. The first record takes the right value but the next one takes also the same value.
1640972229360.png


I guess I reminded you of good old days...
 
Regardless of whether it is the correct way to do it or not, if you put your criteria into a string variable, then debug.print that, that will show you what you have, not what you think you have.
 
= DMax("LOADING_ID", "LOADINGS", "ORDER_ID=" & Forms![LOADINGS]![ORDER_ID] & "") + 1
Your code worked fine at my end.

Open the attachment, create a new record(this will be the third record) and enter a value in the field called yewo, it will generate a value based on your function into the field called owapa.

You can then view the after update event of the field called yewo to see your function.
 

Attachments

Your code worked fine at my end.

Open the attachment, create a new record(this will be the third record) and enter a value in the field called yewo, it will generate a value based on your function into the field called owapa.

You can then view the after update event of the field called yewo to see your function.
Yeah i know that.

I am tyring to apply the code in the default value property of the text box
 
I am tyring to apply the code in the default value property of the text box
To trigger a default property of a textbox(this depends on whether you intend to store the value or not)

if you intend to store the value, then check the attachment i sent, the default value of the text box owapa, is the result of the function.
 
I just want to get the next loading id in a form, so i want to put this command to the property "Default value"
Your code is not putting the calculated value into the default property. Plus, as I said, that isn't the best solution anyway.

Most people assume that field names ending in "ID" are autonumbers or at least numeric. If your Order_ID is not numeric, you have your answer in the error message.
 

Users who are viewing this thread

Back
Top Bottom