Value from combo box in message box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Below you will find my code. On my Parent form I have a CmdButton that opens
a report. What I have so far works, But I would like for the value chosen
from a CboBox in my subform to show up as well. All I can get is the ID
Number "AutoNumber"

---------------What I have working now------------------------
If IsNull(Me![BreedDate]) Then
MsgBox "There is No Breed Date For This Selection At This Time!
" & Chr(13) & Chr(10) & Chr(10) & "You Have Chosen A Female To Breed With ( "
& [Form_Breeders]![Name] & " ) Now You Must Enter a Breed Date! ",
vbExclamation + vbYesNo = vbYes
Cancel = -1
Else
-----------------------------------------------------------------------
---------------What I would like------------------------------------

If IsNull(Me![BreedDate]) Then
MsgBox "There is No Breed Date For This Selection At This Time!
" & Chr(13) & Chr(10) & Chr(10) & "You Have Chosen
(ComboBoxValue_From_SubForm) To Breed With ( " & [Form_Breeders]![Name] & " )
Now You Must Enter a Breed Date! ", vbExclamation + vbYesNo = vbYes
Cancel = -1
Else
 
Alvin

First, if your combo box is constructed in a typical fashion, the first
field is the ID, and is hidden. If you refer to the combo box control in an
expression, you will, by default, get the first field (i.e., the ID).

If you want to refer to the second field, you need to use the .Column(n)
property to point to it -- and .Column() uses zero-based counting, so the
second field in the combo box source is .Column(1).

Next, from your code sample, you've appeared to name your combo box "Name".
This is a reserved word in Access, so you will only confuse yourself and
Access by using this as a field or a control name. May I suggest changing
the table's field name to something like "BreederName", and the control's
name in the form to something like "cboBreederName"?

Regards

Jeff Boyce
<Access MVP>
 
Thank you jeff for the reply,
Maybe you can see a little better with the sample below as to what I'm
needing.
I get the value from the form but not the subform. If you could would you
show me a short example?
Thanks again
Alvin
------------------Start Sample-------------------------------------
If IsNull(Me![BreedDate]) Then
MsgBox "There is No Breed Date For This Selection At This Time!
" & Chr(13) & Chr(10) & Chr(10) &
"You Have Chosen ( " & [Form_Breeders subform]![CboBreadFemale] & " ) To
Breed With ( " & [Form_Breeders]![txtMaleName] & " )
Now You Must Enter a Breed Date! ", vbExclamation + vbYesNo = vbYes
Cancel = -1
Else

--------End Sample--------------------







Jeff Boyce said:
Alvin

First, if your combo box is constructed in a typical fashion, the first
field is the ID, and is hidden. If you refer to the combo box control in an
expression, you will, by default, get the first field (i.e., the ID).

If you want to refer to the second field, you need to use the .Column(n)
property to point to it -- and .Column() uses zero-based counting, so the
second field in the combo box source is .Column(1).

Next, from your code sample, you've appeared to name your combo box "Name".
This is a reserved word in Access, so you will only confuse yourself and
Access by using this as a field or a control name. May I suggest changing
the table's field name to something like "BreederName", and the control's
name in the form to something like "cboBreederName"?

Regards

Jeff Boyce
<Access MVP>

Alvin said:
Below you will find my code. On my Parent form I have a CmdButton that opens
a report. What I have so far works, But I would like for the value chosen
from a CboBox in my subform to show up as well. All I can get is the ID
Number "AutoNumber"

---------------What I have working now------------------------
If IsNull(Me![BreedDate]) Then
MsgBox "There is No Breed Date For This Selection At This Time!
" & Chr(13) & Chr(10) & Chr(10) & "You Have Chosen A Female To Breed With ( "
& [Form_Breeders]![Name] & " ) Now You Must Enter a Breed Date! ",
vbExclamation + vbYesNo = vbYes
Cancel = -1
Else
-----------------------------------------------------------------------
---------------What I would like------------------------------------

If IsNull(Me![BreedDate]) Then
MsgBox "There is No Breed Date For This Selection At This Time!
" & Chr(13) & Chr(10) & Chr(10) & "You Have Chosen
(ComboBoxValue_From_SubForm) To Breed With ( " & [Form_Breeders]![Name] & " )
Now You Must Enter a Breed Date! ", vbExclamation + vbYesNo = vbYes
Cancel = -1
Else
 
Thank you so much Jeff
I Got it , Thank you and I will change the "Name" to MaleName"
Here is the code I used in case someone else might need it.

----------------Code---------------------------
If IsNull(Me![BreedDate]) Then
MsgBox "There is No Breed Date For This Selection At This Time!
" & Chr(13) & Chr(10) & Chr(10) & "You Have Chosen ( " & [Breeders
subform].Form![BreadFemale].Column(1) & " ) To Breed With ( " &
[Form_Breeders]![Name] & " ) Now You Must Enter a Breed Date! ",
vbExclamation + vbYesNo = vbYes
Cancel = -1
Else

--------------------------End--------------------

Jeff Boyce said:
Alvin

First, if your combo box is constructed in a typical fashion, the first
field is the ID, and is hidden. If you refer to the combo box control in an
expression, you will, by default, get the first field (i.e., the ID).

If you want to refer to the second field, you need to use the .Column(n)
property to point to it -- and .Column() uses zero-based counting, so the
second field in the combo box source is .Column(1).

Next, from your code sample, you've appeared to name your combo box "Name".
This is a reserved word in Access, so you will only confuse yourself and
Access by using this as a field or a control name. May I suggest changing
the table's field name to something like "BreederName", and the control's
name in the form to something like "cboBreederName"?

Regards

Jeff Boyce
<Access MVP>

Alvin said:
Below you will find my code. On my Parent form I have a CmdButton that opens
a report. What I have so far works, But I would like for the value chosen
from a CboBox in my subform to show up as well. All I can get is the ID
Number "AutoNumber"

---------------What I have working now------------------------
If IsNull(Me![BreedDate]) Then
MsgBox "There is No Breed Date For This Selection At This Time!
" & Chr(13) & Chr(10) & Chr(10) & "You Have Chosen A Female To Breed With ( "
& [Form_Breeders]![Name] & " ) Now You Must Enter a Breed Date! ",
vbExclamation + vbYesNo = vbYes
Cancel = -1
Else
-----------------------------------------------------------------------
---------------What I would like------------------------------------

If IsNull(Me![BreedDate]) Then
MsgBox "There is No Breed Date For This Selection At This Time!
" & Chr(13) & Chr(10) & Chr(10) & "You Have Chosen
(ComboBoxValue_From_SubForm) To Breed With ( " & [Form_Breeders]![Name] & " )
Now You Must Enter a Breed Date! ", vbExclamation + vbYesNo = vbYes
Cancel = -1
Else
 
Back
Top