F
forcefield via AccessMonster.com
Hi Everyone,
My NotInList combo works almost perfectly (no error message) except that the
record stored in the table is weird.
My NotInList code is :
Private Sub cboScoreBand_NotInList(NewData As String, Response As Integer)
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim sMsg As String
sMsg = "Do You wish to add new '" & NewData & "' in this list?"
If NewData = "" Then Exit Sub
SQuest = MsgBox(sMsg, vbQuestion + vbYesNo, "Add new name?")
If SQuest = vbNo Then
Response = acDataErrContinue
Else
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblScore", dbOpenDynaset)
On Error Resume Next
strSQL = "INSERT INTO tblScore([ScoreBand]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Response = acDataErrAdded
End If
rst.Close
Set rst = Nothing
Set dbs = Nothing
End Sub
The control source for the combo is ScoreBand and the row source is
SELECT DISTINCT tblScore.ScoreBand FROM tblScore WHERE (((tblScore.ScoreBand)
Is Not Null)) ORDER BY tblScore.ScoreBand;
tblScore has 3 text fields FirstName,LastName and ScoreBand and 1 autonumber
ID.
After keying the scoreband for the combo, tblScore result reads like this
ID FirstName LastName ScoreBand
138 Tim Fodger Green
139 Green
140 Peter Seller Red
141 Red
It appears that a duplicated new record is inserted with the same scoreband
Can someone correct my mistakes so that my scoreband is not repeated.?
Thanks
My NotInList combo works almost perfectly (no error message) except that the
record stored in the table is weird.
My NotInList code is :
Private Sub cboScoreBand_NotInList(NewData As String, Response As Integer)
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim sMsg As String
sMsg = "Do You wish to add new '" & NewData & "' in this list?"
If NewData = "" Then Exit Sub
SQuest = MsgBox(sMsg, vbQuestion + vbYesNo, "Add new name?")
If SQuest = vbNo Then
Response = acDataErrContinue
Else
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblScore", dbOpenDynaset)
On Error Resume Next
strSQL = "INSERT INTO tblScore([ScoreBand]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Response = acDataErrAdded
End If
rst.Close
Set rst = Nothing
Set dbs = Nothing
End Sub
The control source for the combo is ScoreBand and the row source is
SELECT DISTINCT tblScore.ScoreBand FROM tblScore WHERE (((tblScore.ScoreBand)
Is Not Null)) ORDER BY tblScore.ScoreBand;
tblScore has 3 text fields FirstName,LastName and ScoreBand and 1 autonumber
ID.
After keying the scoreband for the combo, tblScore result reads like this
ID FirstName LastName ScoreBand
138 Tim Fodger Green
139 Green
140 Peter Seller Red
141 Red
It appears that a duplicated new record is inserted with the same scoreband
Can someone correct my mistakes so that my scoreband is not repeated.?
Thanks