Auto Show on form start

Badvoc

Registered User.
Local time
Today, 20:07
Joined
Apr 22, 2009
Messages
69
Hi
Im using this VBA code to insert a drawing numbers for our engineers.
Code:
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.Text505 = Nz(DMax("MyCounter", "tblAttributesGA")) + 1
Me.txtGADrawingNumber = Nz(DMax("MyCounter", "tblAttributesGA")) + 1 & "-01"
End Sub
At the moment the form will open and you have change a field before the number appears in the txtDrawingNumber field.
What I’d like is that when the form opens the number appears in the txtGAdrawingNumber box straight away.
 
Code:
=Nz(DMax("MyCounter", "tblAttributesGA"),0) + 1 & "-01"
... should go in the Default Value property of txtGADrawingNumber textbox.
 
Code:
=Nz(DMax("MyCounter", "tblAttributesGA"),0) + 1 & "-01"
... should go in the Default Value property of txtGADrawingNumber textbox.

Good idea, but all I get is #NAME? in the txtGADrawingNumber textbox.
 
It's either you are using a read-only form or you've not set the Control Source property of the textbox.
 
The first line (Me.Text505 = Nz(DMax("MyCounter", "tblAttributesGA")) + 1) doesn’t run until the user has clicked in a field so the second line has no data.
Text505 is bound to MyCounter, txtGADrawingNumber is bound to GADrawing in table tblAttributesGA
Let me put it another way, when a form is opened is there a way of making it act as if a user has clicked in a field already.
 
Is MyCounter supposed to be a Primary key for that table?
 
its not, should it be?
this is a database Iv taken over as the chap that complied it left, now Iv been task with making some changes
 
No, just checking. You want this to happen for new records only right? Or is it for those records that don't already have MyCounter set?
 
I think you should leave it as the default behaviour. What will happen is you may end up with discrepancies.
 

Users who are viewing this thread

Back
Top Bottom