Unwanted Blank Lines Are Being Inserted in Listbox

J

John Phelan

I have a list box in which information gets listed from a field (of course).
However, every time I add a new record successfully, a blank line gets added
to the list box. How can I prevent that from happening?

Below is the code I am using behind the form and behind the listbox on the
form:

Form Code (also, see listbox code below)

Option Compare Database
Option Explicit
Private Sub cmdAssignCal_Click()
txtAssignDate = CalendarDlg(txtAssignDate)
ExitLine:
Exit Sub
End Sub

Private Sub cmdDueCal_Click()
txtDueDate = CalendarDlg(txtDueDate)
ExitLine:
Exit Sub
End Sub

Private Sub Form_Current()
Me!TaskIDf =
Forms![team_top_sub_task]![Team_Sub_Tasks]![Team_Sub_tasks_actions].Form!TaskID
Me!Tasks =
Forms![team_top_sub_task]![Team_Sub_Tasks]![Team_Sub_tasks_actions].Form!actionsteps
ExitLine:
Exit Sub
End Sub

Private Sub Form_Load()
ListTeam.Requery
ExitLine:
Exit Sub
End Sub

Private Sub Command14_Click()

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_Command14_Click:
Exit Sub

End Sub

Private Sub Command15_Click()

DoCmd.GoToRecord , , acNewRec

Exit_Command15_Click:
Exit Sub

End Sub

Private Sub Command19_Click()

DoCmd.Close

Exit_Command19_Click:
Exit Sub
End Sub

Private Sub Command21_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Agenda Prep"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command21_Click:
Exit Sub

End Sub

Private Sub Command22_Click()

Dim stDocName As String

stDocName = "Meeting Schedule"
DoCmd.OpenReport stDocName, acPreview

Exit_Command22_Click:
Exit Sub

End Sub

Private Sub Form_Open(Cancel As Integer)
Me!ListTeam.Requery
ExitLine:
Exit Sub
End Sub

Private Sub ListTeam_AfterUpdate()
Dim rst As DAO.Recordset
Dim strcriteria As String
strcriteria = "[taskid]= " & Str$(Nz(Me![ListTeam], 0))

Set rst = Me!Recordset.Clone
rst.FindFirst strcriteria
If rst.NoMatch Then
MsgBox "No entry found.", vbInformation
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
ExitLine:
Exit Sub
End Sub


List Box (that is located on the above form) Code

Option Compare Database
Option Explicit
Private Sub cmdAssignCal_Click()
txtAssignDate = CalendarDlg(txtAssignDate)
ExitLine:
Exit Sub
End Sub

Private Sub cmdDueCal_Click()
txtDueDate = CalendarDlg(txtDueDate)
ExitLine:
Exit Sub
End Sub

Private Sub Form_Current()
Me!TaskIDf =
Forms![team_top_sub_task]![Team_Sub_Tasks]![Team_Sub_tasks_actions].Form!TaskID
Me!Tasks =
Forms![team_top_sub_task]![Team_Sub_Tasks]![Team_Sub_tasks_actions].Form!actionsteps
ExitLine:
Exit Sub
End Sub

Private Sub Form_Load()
ListTeam.Requery
ExitLine:
Exit Sub
End Sub

Private Sub Command14_Click()
On Error GoTo Err_Command14_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_Command14_Click:
Exit Sub

End Sub

Private Sub Command15_Click()

DoCmd.GoToRecord , , acNewRec

Exit_Command15_Click:
Exit Sub

End Sub

Private Sub Command19_Click()

DoCmd.Close

Exit_Command19_Click:
Exit Sub

End Sub

Private Sub Command21_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Agenda Prep"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command21_Click:
Exit Sub

End Sub

Private Sub Command22_Click()

Dim stDocName As String

stDocName = "Meeting Schedule"
DoCmd.OpenReport stDocName, acPreview

Exit_Command22_Click:
Exit Sub

End Sub

Private Sub Form_Open(Cancel As Integer)
Me!ListTeam.Requery
ExitLine:
Exit Sub
End Sub

Private Sub ListTeam_AfterUpdate()
Dim rst As DAO.Recordset
Dim strcriteria As String
strcriteria = "[taskid]= " & Str$(Nz(Me![ListTeam], 0))

Set rst = Me!Recordset.Clone
rst.FindFirst strcriteria
If rst.NoMatch Then
MsgBox "No entry found.", vbInformation
Else
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
ExitLine:
Exit Sub
End Sub

John
 
J

John Vinson

I have a list box in which information gets listed from a field (of course).
However, every time I add a new record successfully, a blank line gets added
to the list box. How can I prevent that from happening?

Below is the code I am using behind the form and behind the listbox on the
form:

Rather than my struggling through 200 lines of code, most or all of
which is irrelevant to the question - let me ask: What is the Row
Source property of the listbox? If it's a Query, please post the SQL.

John W. Vinson[MVP]
 
J

John Phelan

John Vinson said:
Rather than my struggling through 200 lines of code, most or all of
which is irrelevant to the question - let me ask: What is the Row
Source property of the listbox? If it's a Query, please post the SQL.

John W. Vinson[MVP]
SELECT tblTaskOutcomes.TaskID, tblTaskOutcomes.DueDate,
tblTaskOutcomes.Title, tblTaskOutcomes.Priority, tblTaskOutcomes.Status,
tblTaskOutcomes.TaskIDf
FROM tblTaskOutcomes
WHERE
(((tblTaskOutcomes.TaskIDf)=[forms]![sub_tasks_outcomes_top]![sub_tasks_outcomes]![sub_tasks_actions_oc].[form]![TaskID]));
 
J

John Vinson

SELECT tblTaskOutcomes.TaskID, tblTaskOutcomes.DueDate,
tblTaskOutcomes.Title, tblTaskOutcomes.Priority, tblTaskOutcomes.Status,
tblTaskOutcomes.TaskIDf
FROM tblTaskOutcomes
WHERE
(((tblTaskOutcomes.TaskIDf)=[forms]![sub_tasks_outcomes_top]![sub_tasks_outcomes]![sub_tasks_actions_oc].[form]![TaskID]));

And what do you see if you open this Query (assuming that the subform
has a valid TaskID)? Perhaps you just need to put in an additional
criterion (which will depend on your data), such as

AND tblTaskOutcomes.Title IS NOT NULL

to remove records which have a TaskID but no other values.

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Command Button not working on form - HELP!!! 3
Criteria when opening form 1
If Statements 4
Error 2237 8
Missing operator Error 4
Duplicate subForm Info 0
Clear a form 1
Worked in Windows 2000 but not XP 0

Top