PDA

View Full Version : Referring to an Userform



talytech
12-18-2008, 01:24 PM
I'm trying to make a reference to my Userform named "CSSProcessing" from a function. What's the syntax for that? For example, my code returns an error on the following statement:
If UserForms!CSSProcessing![chkAccepted].Value = True And UserForms!CSSProcessing![chkAccepted].Value = False Then
exceptapprvd = "ACCEPTED"


Here is the full code:


myName = ""
For I = 20 To lastrow
'Get Fields
ctrfname = Cells(I, "b").Value
ctrlname = Cells(I, "f").Value
ctrmid = Cells(I, "e").Value
ctrSSN = Cells(I, "i").Value
ctrDOB = Cells(I, "j").Value
ctrVendor = Cells(I, "k").Value
If myName = "" Then
myName = UCase(ctrfname) & Chr(32) & UCase(ctrlname) & ", " & ctrVendor
Else
myName = myName & Chr(13) & UCase(ctrfname) & Chr(32) & UCase(ctrlname) & ", " & ctrVendor
End If
Next
If UserForms!CSSProcessing![chkAccepted].Value = True And UserForms!CSSProcessing![chkAccepted].Value = False Then
exceptapprvd = "ACCEPTED"

theBody = "An exception request for temporary facilities or systems access has been ACCEPTED and processed on " & Date & "for the following individuals:"
theBody = theBody & Chr(13) & myName
theBody = theBody & Chr(13) & "This exception grants contractors a one-time 15 day exception for a temporary access badge or temporary systems access."
theBody = theBody & " If the individual is being issued a badge, please set the expiration date on the temporary access badge issued to 15 days beyond the badge activation date."

ElseIf CSSProcessing![chkAccepted].Value = False And UserForms!CSSProcessing![chkAccepted].Value = True Then
exceptapprvd = "REJECTED"

theBody = "An exception request for temporary facilities or systems access was processed and REJECTED on " & Date & "for the following individuals:"
theBody = theBody & Chr(13) & myName

End If

Set OLF = GetObject("", _
"Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set olMailItem = OLF.Items.Add ' creates a new e-mail message
With olMailItem
.Subject = "EXCEPTION REQUEST FOR TEMPORARY FACILITIES ACCESS (" & exceptapprvd & ")" ' message subject
Set ToContact = .Recipients.Add("e3utbl") '
.Body = theBody '''' Set ToContact = .Recipients.Add("r7uwta")
.Send ' sends the e-mail message (puts it in the Outbox)

End with

Set ToContact = Nothing
Set olMailItem = Nothing
Set OLF = Nothing

End Function

mdmackillop
12-18-2008, 01:37 PM
MsgBox UserForm1.TextBox1.Text

Kenneth Hobs
12-18-2008, 01:42 PM
If you want to get or set the property, the userform should be open.

UserformName.ControlName.Property

Paul_Hossler
12-19-2008, 09:10 AM
If UserForms!CSSProcessing![chkAccepted].Value = True And UserForms!CSSProcessing![chkAccepted].Value = False Then
exceptapprvd = "ACCEPTED"


Am I reading this correct? It sort of reads like you're testing to see if it is both = T and = F


Not tested, but something like this maybe....

If CSSProcessing.chkAccepted And not CSSProcessing.chkAccepted then


Paul

Aussiebear
12-19-2008, 01:30 PM
LOL... Paul are you sure???

lucas
12-19-2008, 01:41 PM
Looks like it to me too.....

Cosmo
12-19-2008, 01:52 PM
Same here. Assuming UserForms!CSSProcessing![chkAccepted].Value" as X, then Line 16 evaluates to:
If X = True And X = False Then
Also, line 24 (aside from the ommitance of "UserForms!" at the beginning of the first statement) will evaluate to:
ElseIf X = False And X = True Then

In this case, since neither of these lines will ever return true, the value of exceptapprvd will never get set, and will cause an error later in the code where it's needed.

I would assume the OP means to use something like...

If CSSProcessing.chkAccepted.Value Then
exceptapprvd = "ACCEPTED"
...
Else
exceptapprvd = "REJECTED"
...
End If

mdmackillop
12-19-2008, 02:48 PM
If UserForms!CSSProcessing![chkAccepted].Value = True And UserForms!CSSProcessing![chkAccepted].Value = False Then
exceptapprvd = "ACCEPTED"


Am I reading this correct? It sort of reads like you're testing to see if it is both = T and = F


Not tested, but something like this maybe....

If CSSProcessing.chkAccepted And not CSSProcessing.chkAccepted then


Paul
Well, if you're going to be picky :rotlaugh:
Never looked at the detail!

talytech
03-04-2009, 09:27 AM
Thanks guys for all your help ... and I'm so STUPID. I'm just getting back to working with this and after reading the threads again I realize that I was checking true and false for the same checkbox .. How STUPID The syntax was right all along... instead of

If UserForms!CSSProcessing![chkAccepted].Value = True And UserForms!CSSProcessing![chkAccepted].Value = False Then
exceptapprvd = "ACCEPTED"


It should've been [chkDenied].value


Thanks again guys ...