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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DMax Question

Status
Not open for further replies.

miltie

Technical User
Nov 4, 2002
15
US
Hello everyone,

Although an easy question for all, I still need assistance.

I have a text box which increments +1 when a new record is added. I have it placed on the control of the text box, but would like to have it automatically run when the form is opened. The code in the control is:

Me.Auto_Num.Text = DMax("Auto_Num", "tblMaster") + 1

Thanks for your help.
Milt
 
Just put that line of code into the OnOpen event of your form.


Private Sub Form_Open(Cancel As Integer)
Me.Auto_Num.Text = DMax("Auto_Num", "tblMaster") + 1
End Sub
 
Thanks for the response. I've tried to put it in the OnOpen event but get the following error:

"You can't reference a property or method for a control unless the control has focus"

Milt
 

Instead of the .Text property use the .Value

Private Sub Form_Open(Cancel As Integer)
Me.Auto_Num.Value = DMax("Auto_Num", "tblMaster") + 1
End Sub

I think you cannot set focus on an object before the form finishes loading.
 
Thanks for the reponse Jerry.

No, it wouldn't let me. I put it in the Open event of the form and I received an error "You can't assign a value to this object."
 
Why are you trying to assign a value to an AutoNumber field?
Kinda defeats the purpose, doesn't it?


Randy
 
Use the Load event procedure instead, as the controls aren't yet loaded when the Open event raises.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top