You could try passing the Form as a parameter to your Sub like this: (not
tested)
Sub Calculation(oForm As Form)
If str_Greet = "Hello" Then oForm.Resultaat.BackColor = RBG(0,255,0)
Else If str_Greet = "Cheers" Then oForm.Resultaat.BackColor =
RGB(255,0,0)
Else: MsgBox("Sorry, I can't hear you")
End If
End Sub
Then when you call the sub:
(Assuming that Resultaat is on the same form)
Private Sub str_Greet_AfterUpdate()
Calculation (Me)
End Sub
Also how does Sub Calculation() know what str_Greet is? Are you storing
this in a global variable? You might want to pass this value in the same way
too, e.g.:
Sub Calculation(strGreet As String, oForm As Form)
If strGreet = "Hello" Then oForm.Resultaat.BackColor = RBG(0,255,0)
Else If strGreet = "Cheers" Then oForm.Resultaat.BackColor =
RGB(255,0,0)
Else: MsgBox("Sorry, I can't hear you")
End If
End Sub
Private Sub str_Greet_AfterUpdate()
Calculation (str_Greet, Me)
End Sub
> I've got this annoying thing where the reference to formfields are not
> recognised in the VBA module if I refer to them by their name only. I
[quoted text clipped - 33 lines]
> Any help welcome, thanks.
> Maarten
Maarten - 14 Feb 2008 10:21 GMT
Hi Jon, thanks for your help.
sorry for the errors in my start post, i wrote it directly into the
newsgroup window, without checking it in VBA.
Where I said 'Resultaat' it should have been 'Result' (Same word,
different language)
str_Greet is also a text field in the form. So the original
programming should have been 'frm_AAA.str_Greet' in stead of just
'str_Greet'
Thanks for your careful reading!
Unfortunately I can't get this to work. I tried the first option (with
only oForm as Form). It returns a type mismatch on "Calculation (Me)"
I gave it a try on using different types (Forms, Variant, ..., either
if it made sense to me or not) and replaced Me in "Calculation (Me)"
by frm_AAA, Form_frm_AAA and Me!.
Any clue?
Maarten - 14 Feb 2008 10:26 GMT
Hi Jon, thanks for your help.
sorry for the errors in my start post, i wrote it directly into the
newsgroup window, without checking it in VBA.
Where I said 'Resultaat' it should have been 'Result' (Same word,
different language)
str_Greet is also a text field in the form. So the original
programming should have been 'frm_AAA.str_Greet' in stead of just
'str_Greet'
Thanks for your careful reading!
Unfortunately I can't get this to work. I tried the first option (with
only oForm as Form). It returns a type mismatch on "Calculation (Me)"
I gave it a try on using different types (Forms, Variant, ..., either
if it made sense to me or not) and replaced Me in "Calculation (Me)"
by frm_AAA, Form_frm_AAA and Me!.
Any clue?
Maarten - 14 Feb 2008 10:27 GMT
Hi Jon, thanks for your help.
sorry for the errors in my start post, i wrote it directly into the
newsgroup window, without checking it in VBA.
Where I said 'Resultaat' it should have been 'Result' (Same word,
different language)
str_Greet is also a text field in the form. So the original
programming should have been 'frm_AAA.str_Greet' in stead of just
'str_Greet'
Thanks for your careful reading!
Unfortunately I can't get this to work. I tried the first option (with
only oForm as Form). It returns a type mismatch on "Calculation (Me)"
I gave it a try on using different types (Forms, Variant, ..., either
if it made sense to me or not) and replaced Me in "Calculation (Me)"
by frm_AAA, Form_frm_AAA and Me!.
Any clue?
Maarten - 14 Feb 2008 10:31 GMT
Hi Jon, thanks for your help.
sorry for the errors in my start post, i wrote it directly into the
newsgroup window, without checking it in VBA.
Where I said 'Resultaat' it should have been 'Result' (Same word,
different language)
str_Greet is also a text field in the form. So the original
programming should have been 'frm_AAA.str_Greet' in stead of just
'str_Greet'
Thanks for your careful reading!
Unfortunately I can't get this to work. I tried the first option (with
only oForm as Form). It returns a type mismatch on "Calculation (Me)"
I gave it a try on using different types (Forms, Variant, ..., either
if it made sense to me or not) and replaced Me in "Calculation (Me)"
by frm_AAA, Form_frm_AAA and Me!.
Any clue?
Maarten - 14 Feb 2008 10:39 GMT
Hi Jon, thanks for your help.
sorry for the errors in my start post, i wrote it directly into the
newsgroup window, without checking it in VBA.
Where I said 'Resultaat' it should have been 'Result' (Same word,
different language)
str_Greet is also a text field in the form. So the original
programming should have been 'frm_AAA.str_Greet' in stead of just
'str_Greet'
Thanks for your careful reading!
Unfortunately I can't get this to work. I tried the first option (with
only oForm as Form). It returns a type mismatch on "Calculation (Me)"
I gave it a try on using different types (Forms, Variant, ..., either
if it made sense to me or not) and replaced Me in "Calculation (Me)"
by frm_AAA, Form_frm_AAA and Me!.
Any clue?
Maarten - 14 Feb 2008 10:52 GMT
Hi Jon, thanks for your help.
sorry for the errors in my start post, i wrote it directly into the
newsgroup window, without checking it in VBA.
Where I said 'Resultaat' it should have been 'Result' (Same word,
different language)
str_Greet is also a text field in the form. So the original
programming should have been 'frm_AAA.str_Greet' in stead of just
'str_Greet'
Thanks for your careful reading!
Unfortunately I can't get this to work. I tried the first option (with
only oForm as Form). It returns a type mismatch on "Calculation (Me)"
I gave it a try on using different types (Forms, Variant, ..., either
if it made sense to me or not) and replaced Me in "Calculation (Me)"
by frm_AAA, Form_frm_AAA and Me!.
Any clue?
Jon Lewis - 14 Feb 2008 11:38 GMT
Sorry - my mistake! You don't need brackets.
Calculation Me
or
Calculation str_Greet, Me
HTH
Jon
> Hi Jon, thanks for your help.
>
[quoted text clipped - 14 lines]
>
> Any clue?
Maarten - 14 Feb 2008 13:12 GMT
Yes it does, it works :) Thanks a bunch! that'll save me quite some
typing.