By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,374 Members | 1,764 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,374 IT Pros & Developers. It's quick & easy.

Capture Unbound Form Control's Value

P: n/a
Hello. I'm trying to capture a controls value: a dropdown box with two
selections (either "Red" or "Blue") keeps returning the value "Red" even if
"Blue" is selected?
Oct 5 '07 #1
Share this Question
Share on Google+
13 Replies


P: n/a
On Oct 5, 12:36 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Hello. I'm trying to capture a controls value: a dropdown box with two
selections (either "Red" or "Blue") keeps returning the value "Red" even if
"Blue" is selected?
Donald, which property are you using to access the value? Could you
post you code as well?

Oct 5 '07 #2

P: n/a
Say I have a control "CboColor" on a form with the "ITEMS" collection set to
list 'Red' and 'Blue' and the "TEXT" value set to 'Red'. I'm trying to get
the value of the control via code as such:

Dim strCboColorVal
strCboColorVal = Me.CboColor.Text()

Then to check if it's working:

Debug.Print(strCboColorVal)

And the value 'Red' occurs even if 'Blue' is selected in the dropdown box.

"Charlie Brown" wrote:
On Oct 5, 12:36 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Hello. I'm trying to capture a controls value: a dropdown box with two
selections (either "Red" or "Blue") keeps returning the value "Red" even if
"Blue" is selected?

Donald, which property are you using to access the value? Could you
post you code as well?

Oct 5 '07 #3

P: n/a
On Oct 5, 1:42 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Say I have a control "CboColor" on a form with the "ITEMS" collection set to
list 'Red' and 'Blue' and the "TEXT" value set to 'Red'. I'm trying to get
the value of the control via code as such:

Dim strCboColorVal
strCboColorVal = Me.CboColor.Text()

Then to check if it's working:

Debug.Print(strCboColorVal)

And the value 'Red' occurs even if 'Blue' is selected in the dropdown box.

"Charlie Brown" wrote:
On Oct 5, 12:36 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Hello. I'm trying to capture a controls value: a dropdown box with two
selections (either "Red" or "Blue") keeps returning the value "Red" even if
"Blue" is selected?
Donald, which property are you using to access the value? Could you
post you code as well?- Hide quoted text -

- Show quoted text -
Try using...

strCboColorVal = Me.CboColor.SelectedItem.Text

Oct 5 '07 #4

P: n/a
..Text is not available for .SelectedItem. I tried .ToString and got same
unwanted result.

"Charlie Brown" wrote:
On Oct 5, 1:42 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Say I have a control "CboColor" on a form with the "ITEMS" collection set to
list 'Red' and 'Blue' and the "TEXT" value set to 'Red'. I'm trying to get
the value of the control via code as such:

Dim strCboColorVal
strCboColorVal = Me.CboColor.Text()

Then to check if it's working:

Debug.Print(strCboColorVal)

And the value 'Red' occurs even if 'Blue' is selected in the dropdown box.

"Charlie Brown" wrote:
On Oct 5, 12:36 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Hello. I'm trying to capture a controls value: a dropdown box with two
selections (either "Red" or "Blue") keeps returning the value "Red" even if
"Blue" is selected?
Donald, which property are you using to access the value? Could you
post you code as well?- Hide quoted text -
- Show quoted text -

Try using...

strCboColorVal = Me.CboColor.SelectedItem.Text

Oct 5 '07 #5

P: n/a
On Oct 5, 2:21 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
.Text is not available for .SelectedItem. I tried .ToString and got same
unwanted result.

"Charlie Brown" wrote:
On Oct 5, 1:42 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Say I have a control "CboColor" on a form with the "ITEMS" collection set to
list 'Red' and 'Blue' and the "TEXT" value set to 'Red'. I'm trying to get
the value of the control via code as such:
Dim strCboColorVal
strCboColorVal = Me.CboColor.Text()
Then to check if it's working:
Debug.Print(strCboColorVal)
And the value 'Red' occurs even if 'Blue' is selected in the dropdown box.
"Charlie Brown" wrote:
On Oct 5, 12:36 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Hello. I'm trying to capture a controls value: a dropdown box with two
selections (either "Red" or "Blue") keeps returning the value "Red" even if
"Blue" is selected?
Donald, which property are you using to access the value? Could you
post you code as well?- Hide quoted text -
- Show quoted text -
Try using...
strCboColorVal = Me.CboColor.SelectedItem.Text- Hide quoted text -

- Show quoted text -
Sorry, I mistyped on that last one...

strCboColorVal = Me.CboColor.SelectedText

Oct 5 '07 #6

P: n/a
That's not working either. Here's a part of what I'm working with:

If DUEDATE < Now() And
frmMain.CboOdueColor.Text = "Red" Then
Debug.Print(frmMain.CboOdueColor.Text)
With oSheet.Range("A" & iRow, "K" &
iRow)
.Font.ColorIndex = 3
Debug.Print("Color Set to RED")
End With
ElseIf DUEDATE < Now() And
frmMain.CboOdueColor.Text = "Blue" Then
Debug.Print(frmMain.CboOdueColor.Text)
With oSheet.Range("A" & iRow, "K" &
iRow)
.Font.ColorIndex = 5
Debug.Print("Color Set to BLUE")
End With
End If
"Charlie Brown" wrote:
On Oct 5, 2:21 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
.Text is not available for .SelectedItem. I tried .ToString and got same
unwanted result.

"Charlie Brown" wrote:
On Oct 5, 1:42 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Say I have a control "CboColor" on a form with the "ITEMS" collection set to
list 'Red' and 'Blue' and the "TEXT" value set to 'Red'. I'm trying to get
the value of the control via code as such:
Dim strCboColorVal
strCboColorVal = Me.CboColor.Text()
Then to check if it's working:
Debug.Print(strCboColorVal)
And the value 'Red' occurs even if 'Blue' is selected in the dropdown box.
"Charlie Brown" wrote:
On Oct 5, 12:36 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Hello. I'm trying to capture a controls value: a dropdown box with two
selections (either "Red" or "Blue") keeps returning the value "Red" even if
"Blue" is selected?
Donald, which property are you using to access the value? Could you
post you code as well?- Hide quoted text -
- Show quoted text -
Try using...
strCboColorVal = Me.CboColor.SelectedItem.Text- Hide quoted text -
- Show quoted text -

Sorry, I mistyped on that last one...

strCboColorVal = Me.CboColor.SelectedText

Oct 5 '07 #7

P: n/a
On Oct 5, 5:13 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
That's not working either. Here's a part of what I'm working with:

If DUEDATE < Now() And
frmMain.CboOdueColor.Text = "Red" Then
Debug.Print(frmMain.CboOdueColor.Text)
With oSheet.Range("A" & iRow, "K" &
iRow)
.Font.ColorIndex = 3
Debug.Print("Color Set to RED")
End With
ElseIf DUEDATE < Now() And
frmMain.CboOdueColor.Text = "Blue" Then
Debug.Print(frmMain.CboOdueColor.Text)
With oSheet.Range("A" & iRow, "K" &
iRow)
.Font.ColorIndex = 5
Debug.Print("Color Set to BLUE")
End With
End If

"Charlie Brown" wrote:
On Oct 5, 2:21 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
.Text is not available for .SelectedItem. I tried .ToString and got same
unwanted result.
"Charlie Brown" wrote:
On Oct 5, 1:42 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Say I have a control "CboColor" on a form with the "ITEMS" collection set to
list 'Red' and 'Blue' and the "TEXT" value set to 'Red'. I'm trying to get
the value of the control via code as such:
Dim strCboColorVal
strCboColorVal = Me.CboColor.Text()
Then to check if it's working:
Debug.Print(strCboColorVal)
And the value 'Red' occurs even if 'Blue' is selected in the dropdown box.
"Charlie Brown" wrote:
On Oct 5, 12:36 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Hello. I'm trying to capture a controls value: a dropdown box with two
selections (either "Red" or "Blue") keeps returning the value "Red" even if
"Blue" is selected?
Donald, which property are you using to access the value? Could you
post you code as well?- Hide quoted text -
- Show quoted text -
Try using...
strCboColorVal = Me.CboColor.SelectedItem.Text- Hide quoted text -
- Show quoted text -
Sorry, I mistyped on that last one...
strCboColorVal = Me.CboColor.SelectedText- Hide quoted text -

- Show quoted text -
Assuming you used the designer property dialog to set the Items
collection by typing Red on the first line, and Blue on the second
line, the follwing code will produce th correct result...

If frmMain.cboOdueColor.SelectedItem.ToString = "Red" Then

....

End If

will give you the result you are looking for.

Oct 6 '07 #8

P: n/a
Still not working. I'm using this code from a separate class to catch/use
the values of the controls but they are only returning the values they were
set to at design time. How to return current values?

Dim strFontSize
strFontSize = frmMain.NumFontSize.Value.ToString
If strFontSize = 10 Then
Debug.Print(strFontSize)
ElseIf strFontSize = 17 Then
Debug.Print(strFontSize)
End If
Dim ODueFontColor, ODueFontColorVal
ODueFontColor = frmMain.CboOdueColor.SelectedItem.ToString
If ODueFontColor = "Red" Then
ODueFontColorVal = 3
Debug.Print(ODueFontColorVal)
ElseIf ODueFontColor = "Blue" Then
ODueFontColorVal = 5
Debug.Print(ODueFontColorVal)
End If
"Charlie Brown" wrote:
On Oct 5, 5:13 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
That's not working either. Here's a part of what I'm working with:

If DUEDATE < Now() And
frmMain.CboOdueColor.Text = "Red" Then
Debug.Print(frmMain.CboOdueColor.Text)
With oSheet.Range("A" & iRow, "K" &
iRow)
.Font.ColorIndex = 3
Debug.Print("Color Set to RED")
End With
ElseIf DUEDATE < Now() And
frmMain.CboOdueColor.Text = "Blue" Then
Debug.Print(frmMain.CboOdueColor.Text)
With oSheet.Range("A" & iRow, "K" &
iRow)
.Font.ColorIndex = 5
Debug.Print("Color Set to BLUE")
End With
End If

"Charlie Brown" wrote:
On Oct 5, 2:21 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
.Text is not available for .SelectedItem. I tried .ToString and got same
unwanted result.
"Charlie Brown" wrote:
On Oct 5, 1:42 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Say I have a control "CboColor" on a form with the "ITEMS" collection set to
list 'Red' and 'Blue' and the "TEXT" value set to 'Red'. I'm trying to get
the value of the control via code as such:
Dim strCboColorVal
strCboColorVal = Me.CboColor.Text()
Then to check if it's working:
Debug.Print(strCboColorVal)
And the value 'Red' occurs even if 'Blue' is selected in the dropdown box.
"Charlie Brown" wrote:
On Oct 5, 12:36 pm, Donald Fisher
<DonaldFis...@discussions.microsoft.comwrote:
Hello. I'm trying to capture a controls value: a dropdown box with two
selections (either "Red" or "Blue") keeps returning the value "Red" even if
"Blue" is selected?
Donald, which property are you using to access the value? Could you
post you code as well?- Hide quoted text -
- Show quoted text -
Try using...
strCboColorVal = Me.CboColor.SelectedItem.Text- Hide quoted text -
- Show quoted text -
Sorry, I mistyped on that last one...
strCboColorVal = Me.CboColor.SelectedText- Hide quoted text -
- Show quoted text -

Assuming you used the designer property dialog to set the Items
collection by typing Red on the first line, and Blue on the second
line, the follwing code will produce th correct result...

If frmMain.cboOdueColor.SelectedItem.ToString = "Red" Then

....

End If

will give you the result you are looking for.

Oct 6 '07 #9

P: n/a
"Donald Fisher" <Do**********@discussions.microsoft.comschrieb
Still not working. I'm using this code from a separate class to
catch/use
the values of the controls but they are only returning the values
they were
set to at design time. How to return current values?

Dim strFontSize
strFontSize = frmMain.NumFontSize.Value.ToString
If strFontSize = 10 Then
Debug.Print(strFontSize)
ElseIf strFontSize = 17 Then
Debug.Print(strFontSize)
End If
Dim ODueFontColor, ODueFontColorVal
ODueFontColor = frmMain.CboOdueColor.SelectedItem.ToString
If ODueFontColor = "Red" Then
ODueFontColorVal = 3
Debug.Print(ODueFontColorVal)
ElseIf ODueFontColor = "Blue" Then
ODueFontColorVal = 5
Debug.Print(ODueFontColorVal)
End If

First, it's strongly recommended to enable Option Strict. This code is slow,
unsafe and is doing unnecessary conversions.

Are you using different instances of the Form? Ist frmMain the visible
instance of the Form that you want to refer to? If you are not sure, set a
break point at the first line and have a look at frmMain.visible.
Armin

Oct 6 '07 #10

P: n/a
I'm not very familiar with option strict but am using explicit at the moment.
As far as I can see there is only one instance of the form frmMain. I set
my break point but how do I look at frmMain.Visible? I know that I can see
my vars etc. in the Autos/Locals windows but am not familiar with the
property you speak.

"Armin Zingler" wrote:
"Donald Fisher" <Do**********@discussions.microsoft.comschrieb
Still not working. I'm using this code from a separate class to
catch/use
the values of the controls but they are only returning the values
they were
set to at design time. How to return current values?

Dim strFontSize
strFontSize = frmMain.NumFontSize.Value.ToString
If strFontSize = 10 Then
Debug.Print(strFontSize)
ElseIf strFontSize = 17 Then
Debug.Print(strFontSize)
End If
Dim ODueFontColor, ODueFontColorVal
ODueFontColor = frmMain.CboOdueColor.SelectedItem.ToString
If ODueFontColor = "Red" Then
ODueFontColorVal = 3
Debug.Print(ODueFontColorVal)
ElseIf ODueFontColor = "Blue" Then
ODueFontColorVal = 5
Debug.Print(ODueFontColorVal)
End If


First, it's strongly recommended to enable Option Strict. This code is slow,
unsafe and is doing unnecessary conversions.

Are you using different instances of the Form? Ist frmMain the visible
instance of the Form that you want to refer to? If you are not sure, set a
break point at the first line and have a look at frmMain.visible.
Armin

Oct 7 '07 #11

P: n/a
Wow! I've got it! At least it's working anyway. I'd still like to learn
about using option strict and "looking" at frmMain.Visible though. I added
some code to the control's ValueChanged property:

Private Sub NumFontSize_ValueChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles NumFontSize.ValueChanged
Dim strFontSizeSel
strFontSizeSel = Me.NumFontSize.Value.ToString
Debug.Print(strFontSizeSel)
strFontSizeglob = strFontSizeSel
Debug.Print(strFontSizeglob)
End Sub

When I fetch strFontSizeglob from my class it works perfect!

"Donald Fisher" wrote:
I'm not very familiar with option strict but am using explicit at the moment.
As far as I can see there is only one instance of the form frmMain. I set
my break point but how do I look at frmMain.Visible? I know that I can see
my vars etc. in the Autos/Locals windows but am not familiar with the
property you speak.

"Armin Zingler" wrote:
"Donald Fisher" <Do**********@discussions.microsoft.comschrieb
Still not working. I'm using this code from a separate class to
catch/use
the values of the controls but they are only returning the values
they were
set to at design time. How to return current values?
>
Dim strFontSize
strFontSize = frmMain.NumFontSize.Value.ToString
If strFontSize = 10 Then
Debug.Print(strFontSize)
ElseIf strFontSize = 17 Then
Debug.Print(strFontSize)
End If
Dim ODueFontColor, ODueFontColorVal
ODueFontColor = frmMain.CboOdueColor.SelectedItem.ToString
If ODueFontColor = "Red" Then
ODueFontColorVal = 3
Debug.Print(ODueFontColorVal)
ElseIf ODueFontColor = "Blue" Then
ODueFontColorVal = 5
Debug.Print(ODueFontColorVal)
End If

First, it's strongly recommended to enable Option Strict. This code is slow,
unsafe and is doing unnecessary conversions.

Are you using different instances of the Form? Ist frmMain the visible
instance of the Form that you want to refer to? If you are not sure, set a
break point at the first line and have a look at frmMain.visible.
Armin
Oct 7 '07 #12

P: n/a
"Donald Fisher" <Do**********@discussions.microsoft.comschrieb
Wow! I've got it! At least it's working anyway. I'd still like to
learn about using option strict
Enable it in the project properties. Right below the Option Explicit
setting.
and "looking" at frmMain.Visible
though.
Visible is a property of the Form. You can examine it in the quick watch,
watch or debug window (? frmMain.visible).

I added some code to the control's ValueChanged property:

Private Sub NumFontSize_ValueChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
NumFontSize.ValueChanged
Dim strFontSizeSel
strFontSizeSel = Me.NumFontSize.Value.ToString
Debug.Print(strFontSizeSel)
strFontSizeglob = strFontSizeSel
Debug.Print(strFontSizeglob)
End Sub

When I fetch strFontSizeglob from my class it works perfect!

"Donald Fisher" wrote:
I'm not very familiar with option strict but am using explicit at
the moment. As far as I can see there is only one instance of the
form frmMain. I set my break point but how do I look at
frmMain.Visible? I know that I can see my vars etc. in the
Autos/Locals windows but am not familiar with the property you
speak.

"Armin Zingler" wrote:
"Donald Fisher" <Do**********@discussions.microsoft.comschrieb
Still not working. I'm using this code from a separate class
to
catch/use
the values of the controls but they are only returning the
values they were
set to at design time. How to return current values?

Dim strFontSize
strFontSize = frmMain.NumFontSize.Value.ToString
If strFontSize = 10 Then
Debug.Print(strFontSize)
ElseIf strFontSize = 17 Then
Debug.Print(strFontSize)
End If
Dim ODueFontColor, ODueFontColorVal
ODueFontColor =
frmMain.CboOdueColor.SelectedItem.ToString If
ODueFontColor = "Red" Then
ODueFontColorVal = 3
Debug.Print(ODueFontColorVal)
ElseIf ODueFontColor = "Blue" Then
ODueFontColorVal = 5
Debug.Print(ODueFontColorVal)
End If
>
>
First, it's strongly recommended to enable Option Strict. This
code is slow, unsafe and is doing unnecessary conversions.
>
Are you using different instances of the Form? Ist frmMain the
visible instance of the Form that you want to refer to? If you
are not sure, set a break point at the first line and have a
look at frmMain.visible.
>
>
Armin
>
>
Oct 8 '07 #13

P: n/a
Thanks for the info. I ended up switching from a numericupdown control to a
dropdown text box since I couldn't get the numericupdown control to update
automatically to the stored setting value. If anyone figures out a working
method to do that please post. Thanks!

"Armin Zingler" wrote:
"Donald Fisher" <Do**********@discussions.microsoft.comschrieb
Wow! I've got it! At least it's working anyway. I'd still like to
learn about using option strict

Enable it in the project properties. Right below the Option Explicit
setting.
and "looking" at frmMain.Visible
though.

Visible is a property of the Form. You can examine it in the quick watch,
watch or debug window (? frmMain.visible).

I added some code to the control's ValueChanged property:

Private Sub NumFontSize_ValueChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
NumFontSize.ValueChanged
Dim strFontSizeSel
strFontSizeSel = Me.NumFontSize.Value.ToString
Debug.Print(strFontSizeSel)
strFontSizeglob = strFontSizeSel
Debug.Print(strFontSizeglob)
End Sub

When I fetch strFontSizeglob from my class it works perfect!

"Donald Fisher" wrote:
I'm not very familiar with option strict but am using explicit at
the moment. As far as I can see there is only one instance of the
form frmMain. I set my break point but how do I look at
frmMain.Visible? I know that I can see my vars etc. in the
Autos/Locals windows but am not familiar with the property you
speak.
>
"Armin Zingler" wrote:
>
"Donald Fisher" <Do**********@discussions.microsoft.comschrieb
Still not working. I'm using this code from a separate class
to
catch/use
the values of the controls but they are only returning the
values they were
set to at design time. How to return current values?
>
Dim strFontSize
strFontSize = frmMain.NumFontSize.Value.ToString
If strFontSize = 10 Then
Debug.Print(strFontSize)
ElseIf strFontSize = 17 Then
Debug.Print(strFontSize)
End If
Dim ODueFontColor, ODueFontColorVal
ODueFontColor =
frmMain.CboOdueColor.SelectedItem.ToString If
ODueFontColor = "Red" Then
ODueFontColorVal = 3
Debug.Print(ODueFontColorVal)
ElseIf ODueFontColor = "Blue" Then
ODueFontColorVal = 5
Debug.Print(ODueFontColorVal)
End If


First, it's strongly recommended to enable Option Strict. This
code is slow, unsafe and is doing unnecessary conversions.

Are you using different instances of the Form? Ist frmMain the
visible instance of the Form that you want to refer to? If you
are not sure, set a break point at the first line and have a
look at frmMain.visible.


Armin

Oct 8 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.