473,480 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with SetFocus

In my application vehicles arrive and depart from a workshop. The
ArrivalDate and the HandoverDate are each entered. Sometimes the
person who should enter the arrival date forgets to do so.

When the vehicle is handed over to the customer and the HandoverDate is
entered I wish to warn about the possibly missing ArrivalDate. In the
BeforeUpdate event of HandoverDate I have:

Private Sub HandoverDate_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.HandoverDate) And IsNull(Me.ArrivalDate) Then
MsgBox "Please enter the Arrival date and then re-enter the
Handover date", ,
"This vehicle appears not to have arrived"
Cancel = True
Me.HandoverDate.Undo
Me.ArrivalDate.SetFocus
End If
End Sub

Everything works fine except for the final SetFocus. This gives rise
the error:
Run-time error 2108: You must save the field before you execute the
SetFocus method.
That is clear enough but I am undoing the entry and cancelling the
update. I guess that the Cancel does not have an effect until the
event routine has exited.

Where do I sensibly put the SetFocus?

I could put it in the AfterUpdate event but I would then have to put
some boolean variable in the BeforeUpdate and test it in AfterUpdate.
Seems a bit too messy.

Aug 7 '06 #1
3 6649
On 7 Aug 2006 03:26:27 -0700, Jim Devenish wrote:
In my application vehicles arrive and depart from a workshop. The
ArrivalDate and the HandoverDate are each entered. Sometimes the
person who should enter the arrival date forgets to do so.

When the vehicle is handed over to the customer and the HandoverDate is
entered I wish to warn about the possibly missing ArrivalDate. In the
BeforeUpdate event of HandoverDate I have:

Private Sub HandoverDate_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.HandoverDate) And IsNull(Me.ArrivalDate) Then
MsgBox "Please enter the Arrival date and then re-enter the
Handover date", ,
"This vehicle appears not to have arrived"
Cancel = True
Me.HandoverDate.Undo
Me.ArrivalDate.SetFocus
End If
End Sub

Everything works fine except for the final SetFocus. This gives rise
the error:
Run-time error 2108: You must save the field before you execute the
SetFocus method.
That is clear enough but I am undoing the entry and cancelling the
update. I guess that the Cancel does not have an effect until the
event routine has exited.

Where do I sensibly put the SetFocus?

I could put it in the AfterUpdate event but I would then have to put
some boolean variable in the BeforeUpdate and test it in AfterUpdate.
Seems a bit too messy.
What Boolean test?

Why cancel the valid Handover entry and then re-enter it just because
a different entry has not been yet made?
Save the Handover entry THEN set focus to the missing Arrival field.

In the Handover AfterUpdate event:

If Not IsNull(Me.HandoverDate) And IsNull(Me.ArrivalDate) Then
MsgBox "This vehicle appears not to have arrived." _
& vbNewLine & "Please enter the Arrival date."
Me.ArrivalDate.SetFocus
End If
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Aug 7 '06 #2
The possible problem with this is - if the user then forgets or ignores
to enter the required arrival date before closing the form, the record
is saved without an arrival date. To overcome this I would have to
make the test when closing the form. Maybe, on balance, that could be a
better place to do the test, preventing the closure of the form if no
arrival date has been entered.

I am wanting to ensure that it is not possible to have a handover date
but no arrival date.
fredg wrote:
>
What Boolean test?

Why cancel the valid Handover entry and then re-enter it just because
a different entry has not been yet made?
Save the Handover entry THEN set focus to the missing Arrival field.

In the Handover AfterUpdate event:

If Not IsNull(Me.HandoverDate) And IsNull(Me.ArrivalDate) Then
MsgBox "This vehicle appears not to have arrived." _
& vbNewLine & "Please enter the Arrival date."
Me.ArrivalDate.SetFocus
End If
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Aug 7 '06 #3
On 7 Aug 2006 07:13:36 -0700, Jim Devenish wrote:
The possible problem with this is - if the user then forgets or ignores
to enter the required arrival date before closing the form, the record
is saved without an arrival date. To overcome this I would have to
make the test when closing the form. Maybe, on balance, that could be a
better place to do the test, preventing the closure of the form if no
arrival date has been entered.

I am wanting to ensure that it is not possible to have a handover date
but no arrival date.

fredg wrote:
>>
What Boolean test?

Why cancel the valid Handover entry and then re-enter it just because
a different entry has not been yet made?
Save the Handover entry THEN set focus to the missing Arrival field.

In the Handover AfterUpdate event:

If Not IsNull(Me.HandoverDate) And IsNull(Me.ArrivalDate) Then
MsgBox "This vehicle appears not to have arrived." _
& vbNewLine & "Please enter the Arrival date."
Me.ArrivalDate.SetFocus
End If
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Re: >preventing the closure of the form if no arrival date has been
entered. <
Forms can display many records.
Don't you mean 'prevent saving the record you are on', rather than
just closing the form.

Place the code in the Form's BeforeUpdate event to prevent leaving the
record without entering the Arrival date if the Handover date has been
entered.

If Not IsNull(Me.HandoverDate) And IsNull(Me.ArrivalDate) Then
MsgBox "This vehicle appears not to have arrived." _
& vbNewLine & "Please enter the Arrival date."
Me.ArrivalDate.SetFocus
End If

Then also place the following code in the Form's BeforeUnload event:

If Not IsNull(Me.HandoverDate) And IsNull(Me.ArrivalDate) Then
MsgBox "This vehicle appears not to have arrived." _
& vbNewLine & "Please enter the Arrival date."
Cancel = True
Me.ArrivalDate.SetFocus
End If

Now you won't be able to close the form without entering the Arrival
date if the Handover date has been entered in the record currently
displayed.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Aug 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10159
by: Corepaul | last post by:
I am a newbie using Access 2000. I am using the following test in the txtAlbum OnExit procedure to prevent leaving an empty text box for a required field If (IsNull(txtAlbum.Value)) Or...
1
2025
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers...
1
5120
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for...
21
5064
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
8
2439
by: sara | last post by:
I have a report that runs fine with data. If there is no data, I have its NO Data event sending a MsgBox and cancelling the report. Then it seems I still get the 2501 message on the Open Report...
2
2975
by: gnewsham | last post by:
I am converting an application from vb.net 2003 to 2005 I have the following function which I call when an input error is detected: Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control) Dim...
5
3262
agroover
by: agroover | last post by:
I can't seem to figure out how to get rid of the errors. I recieve the following error when I leave the Grade.SetFocus in my code... Microsoft Access can't move the focus to the control Grade ...
3
1464
by: Lazster | last post by:
Hello People, I am a newbie here, and if I make some stupid mistakes please forgive me :) I have found this site very helpful, and was hoping someone could solve a problem I have. I have...
1
1824
by: Wayneyh | last post by:
Hello all I am trying to create a search form. I have a table called tblContact which has the field for postcodes in it. I have another table called tblSales which i have created a query to link...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7060
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3013
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.