R
Richard Hollenbeck
Thanks to everyone for your help. Doug Steele, this is the next stage in
the problem you were helping me with yesterday. By the way, I got the table
to update alright, but it's no longer in the error handler, as you will see.
But the problem is that the courseCode is the previous selection from the
previous form.
Why won't the value in the list box change when the value in the list box
changes?
me!requery in the form "frmGroups" doesn't seem to do it. To be sure, just
before I run a query, I run a msgbox to see what the value is and it shows
the current selection. No problem! But when I run the append query, it
applies the query to the previous value of the list box (in the previous
form (which is still open)). Here's my subroutine in "frmGroups":
Private Sub PopulateListBox()
On Error GoTo Err_PopulateListBox
reload_PopulateListBox:
Dim db As DAO.Database, rs As DAO.Recordset, StrSQL As String
'If current course has groups in it. . .
If Nz(DLookup("[groupID]", "[groups]", "[groups].[coursecode] = '" &
Forms!frmSelectCourse!cboSelectCourse & "'"), "") <> "" Then
StrSQL = "SELECT [groups].[groupID] AS [ID],
[groups].[groupDescription] AS [Group], [groups].[groupWeight] AS [Weight]
FROM [groups] WHERE [groups].[courseCode] = '" & Me.courseCode & "'ORDER BY
[groups.groupOrder]"
' I just now tried changing Me.courseCode to
' "Forms!frmSelectCourse!cboSelectCourse"
' but that didn't change anything.
Set db = CurrentDb()
Set rs = db.OpenRecordset(StrSQL, dbOpenDynaset)
Set lstGroups.Recordset = rs ' This all works in an established
course with groups.
Else ' add a group to the course
DoCmd.OpenForm "frmNewGroup", , , , , acDialog 'frmNewGroup is a
modal popup form.
StrSQL = "INSERT INTO groups (courseCode, groupDescription,
groupWeight) VALUES ( '" & Forms!frmSelectCourse!courseCode & "', '" &
Forms!frmNewGroup!txtGD & "', " & Forms!frmNewGroup!txtGW & " )"
CurrentDb.Execute StrSQL, dbFailOnError
DoCmd.Close , "frmNewGroup"
MsgBox Forms!frmSelectCourse!cboSelectCourse
' Maybe I should call Form_Load from here to start over,
' or re-call PopulateListBox (risking an infinite loop)
End If
' If I don't do something like this the form will appear
' totally blank because it couldn't find the courseID which
' is an auto number created when a new group is created.
' the problem is that it is reading the wrong CourseCode
' (a five digit numerical String) from the previous form
' because, for some reason, the course code sticks from
' the previous selection in the previous form.
' If necessary, I'll post the code for the
' cboSelectCourse_OnChange, etc. from
' the previous form.
Exit_PopulateListBox:
Exit Sub
Err_PopulateListBox:
MsgBox "Error " & Err.Number & ", " & vbCrLf & Err.Description,
vbCritical, "case else from Sub PopulateListBox"
Resume Exit_PopulateListBox
End Sub
Many thanks.
Rich Hollenbeck
the problem you were helping me with yesterday. By the way, I got the table
to update alright, but it's no longer in the error handler, as you will see.
But the problem is that the courseCode is the previous selection from the
previous form.
Why won't the value in the list box change when the value in the list box
changes?
me!requery in the form "frmGroups" doesn't seem to do it. To be sure, just
before I run a query, I run a msgbox to see what the value is and it shows
the current selection. No problem! But when I run the append query, it
applies the query to the previous value of the list box (in the previous
form (which is still open)). Here's my subroutine in "frmGroups":
Private Sub PopulateListBox()
On Error GoTo Err_PopulateListBox
reload_PopulateListBox:
Dim db As DAO.Database, rs As DAO.Recordset, StrSQL As String
'If current course has groups in it. . .
If Nz(DLookup("[groupID]", "[groups]", "[groups].[coursecode] = '" &
Forms!frmSelectCourse!cboSelectCourse & "'"), "") <> "" Then
StrSQL = "SELECT [groups].[groupID] AS [ID],
[groups].[groupDescription] AS [Group], [groups].[groupWeight] AS [Weight]
FROM [groups] WHERE [groups].[courseCode] = '" & Me.courseCode & "'ORDER BY
[groups.groupOrder]"
' I just now tried changing Me.courseCode to
' "Forms!frmSelectCourse!cboSelectCourse"
' but that didn't change anything.
Set db = CurrentDb()
Set rs = db.OpenRecordset(StrSQL, dbOpenDynaset)
Set lstGroups.Recordset = rs ' This all works in an established
course with groups.
Else ' add a group to the course
DoCmd.OpenForm "frmNewGroup", , , , , acDialog 'frmNewGroup is a
modal popup form.
StrSQL = "INSERT INTO groups (courseCode, groupDescription,
groupWeight) VALUES ( '" & Forms!frmSelectCourse!courseCode & "', '" &
Forms!frmNewGroup!txtGD & "', " & Forms!frmNewGroup!txtGW & " )"
CurrentDb.Execute StrSQL, dbFailOnError
DoCmd.Close , "frmNewGroup"
MsgBox Forms!frmSelectCourse!cboSelectCourse
' Maybe I should call Form_Load from here to start over,
' or re-call PopulateListBox (risking an infinite loop)
End If
' If I don't do something like this the form will appear
' totally blank because it couldn't find the courseID which
' is an auto number created when a new group is created.
' the problem is that it is reading the wrong CourseCode
' (a five digit numerical String) from the previous form
' because, for some reason, the course code sticks from
' the previous selection in the previous form.
' If necessary, I'll post the code for the
' cboSelectCourse_OnChange, etc. from
' the previous form.
Exit_PopulateListBox:
Exit Sub
Err_PopulateListBox:
MsgBox "Error " & Err.Number & ", " & vbCrLf & Err.Description,
vbCritical, "case else from Sub PopulateListBox"
Resume Exit_PopulateListBox
End Sub
Many thanks.
Rich Hollenbeck