A
ArielZusya
I've got a form (frmPersonExcuse) which has two combo boxes (cmbExcusalReason
and cmbStage). cmbStage is tied to tblMainEvent.Stage and displays values
from tblStage.Stage. cmbStage is also set .visible=False. (I've got it
invisible because I don't want the user to see it or change it but I want to
be able to refer to it in code... see below. Incidentally, thinking this
might be a problem I tried making it visible and it had no impact on this
problem.) tblMainEvent is linked to tblStage in a one to many relationship
tblMainEvent.Stage to tblStage.ID_Stage. cmbReason is tied to
tblMainEvent.Reason and displays values from tblReason.Reason. cmbReason is
set .visible=True. tblMainEvent is linked to tblReason in a one to many
relationship tblMainEvent.Reason to tblReason.ID_Reason.
tblStage has three values:
1 Pre
2 Individual
3 Group
tblReason has 5 values:
1 N/A
2 Hardship
3 Cause
4 Pros
5 Def
When the form loads I run the following script:
'***Start Code ***
Private Sub Form_Load()
Dim strSQLHolder As String
Dim strSQLStarter As String
Dim strSQLMiddle1 As String
Dim strSQLMiddle2 As String
Dim strSQLEnder As String
strSQLStarter = "SELECT tblReason.* FROM tblReason "
strSQLMiddle1 = "WHERE (((tblReason.ID_Reason)=2)) " & vbCrLf & _
"OR (((tblReason.ID_Reason)=3)) "
strSQLMiddle2 = "WHERE (((tblReason.ID_Reason)<>1)) "
strSQLEnder = "ORDER BY tblReason.ID_Reason;"
Select Case Me.cmbStage
Case 1, 2 'Pre & Individual
strSQLHolder = strSQLStarter & strSQLMiddle1 & strSQLEnder
Case 3 'Group
strSQLHolder = strSQLStarter & strSQLMiddle2 & strSQLEnder
End Select
Me.cmbExcusalReason.RowSource = strSQLHolder
End Sub
'***End Code ****
Note: I added that vbCrLf to strSQLMiddle1 so it would wrap nicely in this
question. In my code I have that all on one line.
When the form loads cmbReason displays blanks where there should be values
in the dropdown list. The number of blanks corresponds to the correct number
of values based on the above queries and cases but no values actually appear.
Further, if I select the blank from the dropdown list that corresponds to
where the value I want should be and then I try to close the form I get the
following error:
"The value you entered isn't valid for this field. For example, you may have
entered text in a numberic field or a number that is larger than the
FieldSize setting permits."
and then when I click OK I get the following error:
"You can't save this record at this time. MyDB may have encounted an error
while trying to save a record. If you close this object now, the data changes
you made will be lost. Do you want to close the database object anyway?"
What have I done now? I thought I was finally getting the hang of all this.
Why is my cmbReason not showing me values? Why can't I select a value and
have it save to tblMainEvent? What little hair I have left is falling out.
Your help is greatly appreciated!
and cmbStage). cmbStage is tied to tblMainEvent.Stage and displays values
from tblStage.Stage. cmbStage is also set .visible=False. (I've got it
invisible because I don't want the user to see it or change it but I want to
be able to refer to it in code... see below. Incidentally, thinking this
might be a problem I tried making it visible and it had no impact on this
problem.) tblMainEvent is linked to tblStage in a one to many relationship
tblMainEvent.Stage to tblStage.ID_Stage. cmbReason is tied to
tblMainEvent.Reason and displays values from tblReason.Reason. cmbReason is
set .visible=True. tblMainEvent is linked to tblReason in a one to many
relationship tblMainEvent.Reason to tblReason.ID_Reason.
tblStage has three values:
1 Pre
2 Individual
3 Group
tblReason has 5 values:
1 N/A
2 Hardship
3 Cause
4 Pros
5 Def
When the form loads I run the following script:
'***Start Code ***
Private Sub Form_Load()
Dim strSQLHolder As String
Dim strSQLStarter As String
Dim strSQLMiddle1 As String
Dim strSQLMiddle2 As String
Dim strSQLEnder As String
strSQLStarter = "SELECT tblReason.* FROM tblReason "
strSQLMiddle1 = "WHERE (((tblReason.ID_Reason)=2)) " & vbCrLf & _
"OR (((tblReason.ID_Reason)=3)) "
strSQLMiddle2 = "WHERE (((tblReason.ID_Reason)<>1)) "
strSQLEnder = "ORDER BY tblReason.ID_Reason;"
Select Case Me.cmbStage
Case 1, 2 'Pre & Individual
strSQLHolder = strSQLStarter & strSQLMiddle1 & strSQLEnder
Case 3 'Group
strSQLHolder = strSQLStarter & strSQLMiddle2 & strSQLEnder
End Select
Me.cmbExcusalReason.RowSource = strSQLHolder
End Sub
'***End Code ****
Note: I added that vbCrLf to strSQLMiddle1 so it would wrap nicely in this
question. In my code I have that all on one line.
When the form loads cmbReason displays blanks where there should be values
in the dropdown list. The number of blanks corresponds to the correct number
of values based on the above queries and cases but no values actually appear.
Further, if I select the blank from the dropdown list that corresponds to
where the value I want should be and then I try to close the form I get the
following error:
"The value you entered isn't valid for this field. For example, you may have
entered text in a numberic field or a number that is larger than the
FieldSize setting permits."
and then when I click OK I get the following error:
"You can't save this record at this time. MyDB may have encounted an error
while trying to save a record. If you close this object now, the data changes
you made will be lost. Do you want to close the database object anyway?"
What have I done now? I thought I was finally getting the hang of all this.
Why is my cmbReason not showing me values? Why can't I select a value and
have it save to tblMainEvent? What little hair I have left is falling out.
Your help is greatly appreciated!