I am struggling with a piece of code which leads to the error described
in the title of thiis message. The code stops at "Public Function
TestRockDescriptionForUniqueness() As Boolean" in the second function
listed. Anybody see a mistake(s)?
Duke
Private Function ValidData() As Boolean
Dim strMessage As String
If txtNewGemName = "" Then
txtNewGemName.SetFocus
strMessage = "You must enter the name of the new gem."
ValidData = False
Else
If Not TestRockDescriptionForUniqueness Then
ValidData = False
MsgBox "The Add New Gem value is already taken",
vbExclamation, "Duplicate gem name"
Else
ValidData = True
End If
End If
End Function
=====
Public Function TestRockDescriptionForUniqueness() As Boolean
Dim rs As Recordset
Set rs = New Recordset
rs = FindRockCodeTable
TestRockDescriptionForUniqueness = True
With rs
Do Until .EOF
If !RockDescription = txtAddNewGem Then
TestRockDescriptionForUniqueness = False
End If
Loop
End Function
=========
Public Function FindRockCodeTable() As Recordset
Set rsRockCodeTable = New Recordset
rsRockCodeTable.Open "SELECT GemID, GemDesciption FROM RockCode"
FindRockCodeTable = rsRockCodeTable
End Function
Henning - 29 Jul 2006 00:48 GMT
> I am struggling with a piece of code which leads to the error described
> in the title of thiis message. The code stops at "Public Function
[quoted text clipped - 28 lines]
> Do Until .EOF
> If !RockDescription = txtAddNewGem Then
Where is RockDescription defined? Or should it be GemDesciption?
> TestRockDescriptionForUniqueness = False
> End If
> Loop
Missing End With
> End Function
>
[quoted text clipped - 5 lines]
> FindRockCodeTable = rsRockCodeTable
> End Function
Add Option Explicit at the very top of Forms and Modules to reduce spelling
errors.
/Henning
Henning - 29 Jul 2006 01:26 GMT
> I am struggling with a piece of code which leads to the error described
> in the title of thiis message. The code stops at "Public Function
[quoted text clipped - 40 lines]
> FindRockCodeTable = rsRockCodeTable
> End Function
Also, this can't be all the code. So it's hard to point out any more errors.
How do you connect to and open the database?
I would move the connection and the query in FindRockCode() to
TestRockDescriptionForUniqueness().
Recordset is never closed.
/Henning
Steve Gerrard - 29 Jul 2006 02:36 GMT
>I am struggling with a piece of code which leads to the error described
> in the title of thiis message. The code stops at "Public Function
> TestRockDescriptionForUniqueness() As Boolean" in the second function
> listed. Anybody see a mistake(s)?
> rs = FindRockCodeTable
needs to be
Set rs = FindRockCodeTable
also
> Set rs = New Recordset
serves no purpose there.
Similarly,
> FindRockCodeTable = rsRockCodeTable
needs to be
Set FindRockCodeTable = rsRockCodeTable
Finally,
> rsRockCodeTable.Open "SELECT GemID, GemDesciption FROM RockCode"
is unlikely to work since no connection to any database is specified.