If Statement

D

DS

I have an If statement to set a field, this is in a module.
I'm getting variable not defined error.
Any help is appreciated.
Thanks
DS

Public Function Response(frm As Form) As String
Select Case frm!TxtCode.value
Case "AB"
DoCmd.OpenForm "frmMsgCC"
If frm = "frmFXRefundCC" Then
Forms!frmMsgCC!TxtAction = 1
ElseIf frm = "frmPadPreAuth" Then
Forms!frm!frmMsgCC!TxtAction = 2
End If
Forms!frmMsgCC!TxtMsg = "(AB) ABORTED"
Forms!frmMsgCC!TxtMsg2 = "Upstream System Error, Try Again
Later"
End Select
 
R

RonaldoOneNil

You need to compare the name of your form to the string

If frm.Name = "frmFXRefundCC" Then
 
D

DS

Thank You, but the value isn't being passed. For whatever reason.

DoCmd.OpenForm "frmMsgCC"
If frm.NAME = "frmFXRefundCC" Then
Forms!frmMsgCC!TxtClose = 1
ElseIf frm.NAME = "frmOrderScreen" Then
Forms!frmMsgCC!TxtClose = 2
End If
Forms!frmMsgCC!TxtMsg = "(AB) ABORTED"
Forms!frmMsgCC!TxtMsg2 = "Upstream System Error, Try Again Later"

Thanks
DS
 
J

Jim Burke in Novi

I can't figure out why you're passing the form as an object when all you care
about is the name of the form and the value of TxtCode. I would just pass the
form name and the TxtCode values as String variables. But if you're stuck
with that logic as it is ...

You didn't mention which statement is causing the error. Is it the statement
where you reference the form name? It seems to me that one source of a
problem would be this statement:

Select Case frm!TxtCode.value

You're passing 'frm' as a form object (which I have never tried), so I would
think you'd need something like frm.Controls("TxtCode").Value or something
along those lines. I'm pretty sure if you pass the form object, you don't
refernce fields from that object using the Forms!.. method.
 
D

DS

Your right all I do care about is the name of the form, not the object
itself. So how would I pass just the name?
Thanks
DS
 
J

Jim Burke in Novi

In each form's subroutine wherever you're doing the call, just put

Call Routine(me.name, txtCode.value)

to pass the form name and the textbox value. In the sub or function, use

Public Sub Routine(byval formName as string, byval txtCodeValue as string)
 

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