You are making it harder than it really is.
All you really need is:
DMax("[NRCRT]","[CZIS") + 1
If the tex box is an unbound control, you can put it in the control's
Control Source property like this:
=DMax("[NRCRT]","[CZIS") + 1
If the text box is a bound control, put it in the form's Current event
like
this:
Me.MyTextBox = DMax("[NRCRT]","[CZIS") + 1
--
Dave Hargis, Microsoft Access MVP
Florin said:
Because I need max value +1 in a text box.
My problem is that text box isn't populate without activate Combobox
(with click or enter,).
User need modify value in textbox, if that is necessary, and I don't want
force user to make click on Combobox (because user forget that)
Klatuu said:
Since it returns only one row, why is it a combo?
Have you tried my original idea of using the form current event?
--
Dave Hargis, Microsoft Access MVP
:
yes, it have :
- SELECT DISTINCTROW max([CZIS].[NRCRT]) FROM [CZIS];
Does the combo have a row source?
--
Dave Hargis, Microsoft Access MVP
:
Event AfterUpdate have sens when I
generate an event (click or enter, etc) on ComboBox.
I want populate the text box during open the form, without direct
action
on ComboBox.
ComboBox have only one record (=max of field).
Use the form's Current event. It will set the correct value for
the
text
box
each time you go to a different record. The only issue you will
have is
for
new records, so you will need to also populate the text box in
the
combo's
After Update event. The way I would do it is put the code in a
Sub
in
the
form's module and call it from the form Current event and the
combo
After
Update event:
Private Sub Form_Current()
If Not Me.NewRecord Then
call SetTextBoxValue
End If
End Sub
Private Sub MyCombo_AfterUpdate()
Call SetTextBoxValue
End Sub
Private Sub SetTextBoxValue()
Me.MyTextBox = Me.MyCombo + 1
End Sub
--
Dave Hargis, Microsoft Access MVP
:
Is it possible , in VB, to create same result to "on click"
event?
My problem is that I have a form with a combo box and a text
box.
When I open form, I want
Text box=Combo box+1
without make click on Combo box.
Combo box have singular record (=max of field)
In normal condition:
1 open form
2 click on Combo box => after update event =>rezult value in
Text
box
but I don't click on Combo box.
How can I activate record in combo box, without click.
PS Excuse me for my english language!
Thanks in Advance!