473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 6645
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
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
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
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
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
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
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
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
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
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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
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...

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.