Run-Time Error 2108

mcdhappy80

Registered User.
Local time
Today, 14:16
Joined
Jun 22, 2009
Messages
347
I'm receiving this error:

RTE2108.jpg


I tried this two lines of code (before the bolded one which causes error)
Code:
Me.intDana2.Undo
Me.intDana1.SetFocus
[B]Me.intDana2.Visible = False[/B]
First to empty the field intDana2, which I want to hide, because I don't need to save it, and second to change focus on other field, but now I'm getting the above message that I need to save the field.
How do I fix this?
Thank You.
 
Last edited:
is this in a controls before_update event

i dont think you can transfer program control to a different form control in a controls BEFORE UPDATE event. You have to either undo, or enter a satisfactory value, but you cannot undo AND transfer control

I was trying to do this not 5 minutes ago, with the same issue!
 
The code is bound to intDana2 text field controls Before Update event.
So is there something else I can do?
 
Create a flag -

Code:
Private blnFlag As Boolean

in the declarations section of the form in question.

Then, in the Before Update event, put

Code:
blnFlag = True

if you want the focus to be set.

Then in the form's AFTER UPDATE event put
Code:
If blnFlag Then 
   Me.intDana1.SetFocus
   Me.intDana2.Visible = False
End If
 
Create a flag -

Code:
Private blnFlag As Boolean
in the declarations section of the form in question.

Then, in the Before Update event, put

Code:
blnFlag = True
if you want the focus to be set.

Then in the form's AFTER UPDATE event put
Code:
If blnFlag Then 
   Me.intDana1.SetFocus
   Me.intDana2.Visible = False
End If

In which of the forms events I need to enter, in order to get to the declaration section?
 
In which of the forms events I need to enter, in order to get to the declaration section?

Just go to any event in the form and the General declarations section is at the very top just under the part that says:

Option Compare Database
Option Explicit

if you have the Option Explicit (which is good to have anyway so you don't end up with undeclared variables).
 
Just go to any event in the form and the General declarations section is at the very top just under the part that says:

Option Compare Database
Option Explicit

if you have the Option Explicit (which is good to have anyway so you don't end up with undeclared variables).
Ok, thanks Bob. I will try this method :)

Now that You mentioned Option Explicit part, I have to say that I had it in my code, but I needed to remove it because in one of my IF statements I have the part Cancel = True (to quite the function if that IF condition is true). With the Option Explicit turned On I was getting an error that Cancel is not declared (which was correct).
How do I fix this? As what type should I declare Cancel then, or is there another method to do this?
 
When You say BEFORE UPDATE event do You mean the controls or forms before update event?
 
If Cancel is not declared, it is because you were trying to cancel something that does not support a cancel operation.

For simple case, I don't have to declare Cancel in a Form_Open event because the automatic declaration thereof lists Form_Open(Cancel as Integer). The variable Cancel is a "formal parameter" and as such, is declared. But if you tried to cancel the Form_Load event, that particular event doesn't support cancellation. In THAT context, you would have to declare a variable called Cancel - and would have no convenient way to do anything useful with it if you did.

By the same logic, you can use Cancel in Form_Unload but not in Form_Close. Because Form_Open(Cancel as Integer) is the first event in the sequence that fires when a form opens, and Form_Unload(Cancel as Integer) is the first event in the sequence that fires when a form closes.

Put back Option Explicit and instead find out whether you are trying to cancel an uncancellable event.
 
If Cancel is not declared, it is because you were trying to cancel something that does not support a cancel operation.

For simple case, I don't have to declare Cancel in a Form_Open event because the automatic declaration thereof lists Form_Open(Cancel as Integer). The variable Cancel is a "formal parameter" and as such, is declared. But if you tried to cancel the Form_Load event, that particular event doesn't support cancellation. In THAT context, you would have to declare a variable called Cancel - and would have no convenient way to do anything useful with it if you did.

By the same logic, you can use Cancel in Form_Unload but not in Form_Close. Because Form_Open(Cancel as Integer) is the first event in the sequence that fires when a form opens, and Form_Unload(Cancel as Integer) is the first event in the sequence that fires when a form closes.

Put back Option Explicit and instead find out whether you are trying to cancel an uncancellable event.

In most of my cases I was trying to cancel the Before Update event of a textfield control, but I think this Cancel was in text field controls AfterUpdate event. Here is one sample code:
Code:
Private Sub dteOd1_AfterUpdate()
'Polje dteOd1; After Update - Funkcija za racunanje datuma za god odmor
Dim txtDana1 As String
Dim lngDana1 As Long
Dim dteDo1 As Date

If IsNull(Me.intDana1) Or IsNull(Me.dteOd1) Then
    If IsNull(Me.intDana1) Then
        MsgBox ("Morate uneti broj radnih dana odmora")
        Me.intDana1.SetFocus
    End If
    If IsNull(Me.dteOd1) Then
        MsgBox ("Morate uneti datum pocetka odmora")
        Me.dteOd1.SetFocus
    End If
    Cancel = True
Else
    txtDana1 = Me.intDana1

    lngDana1 = CLng(txtDana1)
    
    dteJavi1 = dhAddWorkDaysA(lngDana1, Me.dteOd1, Array(#1/1/2009#, #2/1/2009#, #7/1/2009#, #2/15/2009#, #4/17/2009#, #4/20/2009#, #1/5/2009#, #2/5/2009#))
    Me.dteJavi1 = dteJavi1
    
    dteDo1 = dhAddWorkDaysA(lngDana1, Me.dteOd1, Array(#1/1/2009#, #2/1/2009#, #7/1/2009#, #2/15/2009#, #4/17/2009#, #4/20/2009#, #1/5/2009#, #2/5/2009#), True)
    Me.dteDo1 = dteDo1
End If

End Sub
Could You write down how should I declare it?
Thank You.
 
You can't use Cancel = True in an After Update event. It has already happened so you can't cancel.
 
Put the code in the control's BEFORE UPDATE using the method I showed for the form's Before Update event and use the flag and check the flag in the control's After Update event to see if you need to set focus on the particular control.
 
Put the code in the control's BEFORE UPDATE using the method I showed for the form's Before Update event and use the flag and check the flag in the control's After Update event to see if you need to set focus on the particular control.

Thank You Bob, will do :)
 

Users who are viewing this thread

Back
Top Bottom