Problems after enter press.

L

ldiaz

Hello all.
I have this code, but when I enter a value and press enter, the set focus
goes directly to first line of the records of the subform,

I think the problem is the setfocus event, but how can I solve this?
Thanks in advanced.
=============================
Private Sub DT_Min_AfterUpdate()
Me.Recalc

If ([Forms]![frm_Production_Report]![TSum]) > 60 Then
MsgBox "You can't report a value greater that 60 Minutes!", vbCritical,
"Error, exceed value"
'Delete value
Me.DT_Min = "1"
'pass code
Me.DT_Code.SetFocus
'focus
Me.DT_Min.SetFocus

ElseIf IsNull(Me.DT_Min) Or Me.DT_Min < 1 Then

MsgBox "Zero or Null value, select a value beetween 1 and 60", vbCritical,
"Zero or Null value error"
'Delete value
Me.DT_Min = "1"
'pass code
Me.DT_Code.SetFocus
'focus
Me.DT_Min.SetFocus


Else
Me.Comments.SetFocus
End If


End Sub
=============================
 
B

BruceM

It is not clear what you are trying to do. What I see is that in the After
Update event of the control DT_Min you are checking the value in the TSum
field or control on another form (frm_Production_Report). If the current
form is frm_Production_Report you can just use the Me prefix: Me.TSum.

You say you are deleting the value, but then you set it to 1. After that
you set control to DT_Code, then to DT_Min.

If you need to validate the entry in a control, use the Before Update event,
which can be canceled. After Update may be too late for your needs.

Private Sub DT_Min_BeforeUpdate()

If Me.DT_Min > 60 Then
MsgBox "60 maximum"
Cancel = True
End If

If this does not address the problem, describe what you hope to accomplish.
Include names of controls. I usually name the control something other than
the field name (e.g. txtDT_Min) to avoid confusion, both for myself and
Access, which can in some cases become addled when trying to deal with a
field and control that share the same name.
 
L

ldiaz

it's now fixed, thanks

right now I have a similar problem.


how can I make this operation:
me.form.recalc

without lost the setfocus on the row?

Thanks
LD

--
Lorenzo Díaz
Cad Technician


BruceM said:
It is not clear what you are trying to do. What I see is that in the After
Update event of the control DT_Min you are checking the value in the TSum
field or control on another form (frm_Production_Report). If the current
form is frm_Production_Report you can just use the Me prefix: Me.TSum.

You say you are deleting the value, but then you set it to 1. After that
you set control to DT_Code, then to DT_Min.

If you need to validate the entry in a control, use the Before Update event,
which can be canceled. After Update may be too late for your needs.

Private Sub DT_Min_BeforeUpdate()

If Me.DT_Min > 60 Then
MsgBox "60 maximum"
Cancel = True
End If

If this does not address the problem, describe what you hope to accomplish.
Include names of controls. I usually name the control something other than
the field name (e.g. txtDT_Min) to avoid confusion, both for myself and
Access, which can in some cases become addled when trying to deal with a
field and control that share the same name.


ldiaz said:
Hello all.
I have this code, but when I enter a value and press enter, the set focus
goes directly to first line of the records of the subform,

I think the problem is the setfocus event, but how can I solve this?
Thanks in advanced.
=============================
Private Sub DT_Min_AfterUpdate()
Me.Recalc

If ([Forms]![frm_Production_Report]![TSum]) > 60 Then
MsgBox "You can't report a value greater that 60 Minutes!", vbCritical,
"Error, exceed value"
'Delete value
Me.DT_Min = "1"
'pass code
Me.DT_Code.SetFocus
'focus
Me.DT_Min.SetFocus

ElseIf IsNull(Me.DT_Min) Or Me.DT_Min < 1 Then

MsgBox "Zero or Null value, select a value beetween 1 and 60", vbCritical,
"Zero or Null value error"
'Delete value
Me.DT_Min = "1"
'pass code
Me.DT_Code.SetFocus
'focus
Me.DT_Min.SetFocus


Else
Me.Comments.SetFocus
End If


End Sub
=============================
 
B

BruceM

I have not been able to duplicate the problem. How are you running the
code, and for what reason?

ldiaz said:
it's now fixed, thanks

right now I have a similar problem.


how can I make this operation:
me.form.recalc

without lost the setfocus on the row?

Thanks
LD

--
Lorenzo Díaz
Cad Technician


BruceM said:
It is not clear what you are trying to do. What I see is that in the
After
Update event of the control DT_Min you are checking the value in the TSum
field or control on another form (frm_Production_Report). If the current
form is frm_Production_Report you can just use the Me prefix: Me.TSum.

You say you are deleting the value, but then you set it to 1. After that
you set control to DT_Code, then to DT_Min.

If you need to validate the entry in a control, use the Before Update
event,
which can be canceled. After Update may be too late for your needs.

Private Sub DT_Min_BeforeUpdate()

If Me.DT_Min > 60 Then
MsgBox "60 maximum"
Cancel = True
End If

If this does not address the problem, describe what you hope to
accomplish.
Include names of controls. I usually name the control something other
than
the field name (e.g. txtDT_Min) to avoid confusion, both for myself and
Access, which can in some cases become addled when trying to deal with a
field and control that share the same name.


ldiaz said:
Hello all.
I have this code, but when I enter a value and press enter, the set
focus
goes directly to first line of the records of the subform,

I think the problem is the setfocus event, but how can I solve this?
Thanks in advanced.
=============================
Private Sub DT_Min_AfterUpdate()
Me.Recalc

If ([Forms]![frm_Production_Report]![TSum]) > 60 Then
MsgBox "You can't report a value greater that 60 Minutes!", vbCritical,
"Error, exceed value"
'Delete value
Me.DT_Min = "1"
'pass code
Me.DT_Code.SetFocus
'focus
Me.DT_Min.SetFocus

ElseIf IsNull(Me.DT_Min) Or Me.DT_Min < 1 Then

MsgBox "Zero or Null value, select a value beetween 1 and 60",
vbCritical,
"Zero or Null value error"
'Delete value
Me.DT_Min = "1"
'pass code
Me.DT_Code.SetFocus
'focus
Me.DT_Min.SetFocus


Else
Me.Comments.SetFocus
End If


End Sub
=============================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top