Help: Can someone Please Explain why the following happens 
Author Message
 Help: Can someone Please Explain why the following happens

I have the following Public Function that creates an auto field based on
criteria.

I was originally programming only in ADO but have had to add DAO becasuse I
can not seem to figure why a recordset will not be created. I am having
problems at lines 22 and 23 of the code below. Line 22 (ADO) will not return
my records and line 23 (DAO) will.  Can anyone give me a clue as to why line
22 always returns an empty record set?

Line 24 was active when I was oringinally programming. It was where I
noticed the null recordset occuring when I had records in the table.

gsDistrict and gCon are set globally

1    Public Function AutoID(vTable As Variant, vFld As Variant, Optional
vPrefix As Variant)
2    'Create a new key by combining the user initials with an integer and
optionally a Prefix
3    'to create a unique key
4      Dim rsADO As ADODB.Recordset
5     Dim rs As DAO.Recordset
6      Dim db As Database
7      Dim lCnt As Long
8      Dim sLastID As String
9      Dim wCnt As Integer
10     Dim sPrefix As String
11     Dim sInitials As String

12   On Error GoTo AutoID_Err

13    Set db = CurrentDb()

14    If IsMissing(vPrefix) Then
15      sPrefix = ""
16    Else
17      sPrefix = "" & LCase(vPrefix)
18    End If

20    sInitials = sPrefix & gsDistrict

21    Set rsADO = New ADODB.Recordset
22    rsADO.Open "SELECT " & vTable & ".* FROM " & vTable & " WHERE " & vFld
& " Like '" & sInitials & "*';", gCon, adOpenDynamic, adLockOptimistic

23    Set rs = db.OpenRecordset("SELECT " & vTable & ".* FROM " & vTable & "
WHERE " & vFld & " Like '" & sInitials & "*';", dbOpenSnapshot)

24   'If rsADO.EOF Then
25    If rs.EOF Then
26      AutoID = sInitials & "000001"
27    Else

28+   Rest of routine to generate unique number/key/name...



Mon, 15 Apr 2002 03:00:00 GMT  
 Help: Can someone Please Explain why the following happens
Sorry:

Forgot to say, Please reply to me at:


I am leaving town for a few days and my news server will have dropped any
replies by the time I get back.

TIA

Mark Layne
Arthur Langhus Layne - LLC

www.all-llc.com


Quote:
> I have the following Public Function that creates an auto field based on
> criteria.

> I was originally programming only in ADO but have had to add DAO becasuse
I
> can not seem to figure why a recordset will not be created. I am having
> problems at lines 22 and 23 of the code below. Line 22 (ADO) will not
return
> my records and line 23 (DAO) will.  Can anyone give me a clue as to why
line
> 22 always returns an empty record set?

> Line 24 was active when I was oringinally programming. It was where I
> noticed the null recordset occuring when I had records in the table.

> gsDistrict and gCon are set globally

> 1    Public Function AutoID(vTable As Variant, vFld As Variant, Optional
> vPrefix As Variant)
> 2    'Create a new key by combining the user initials with an integer and
> optionally a Prefix
> 3    'to create a unique key
> 4      Dim rsADO As ADODB.Recordset
> 5     Dim rs As DAO.Recordset
> 6      Dim db As Database
> 7      Dim lCnt As Long
> 8      Dim sLastID As String
> 9      Dim wCnt As Integer
> 10     Dim sPrefix As String
> 11     Dim sInitials As String

> 12   On Error GoTo AutoID_Err

> 13    Set db = CurrentDb()

> 14    If IsMissing(vPrefix) Then
> 15      sPrefix = ""
> 16    Else
> 17      sPrefix = "" & LCase(vPrefix)
> 18    End If

> 20    sInitials = sPrefix & gsDistrict

> 21    Set rsADO = New ADODB.Recordset
> 22    rsADO.Open "SELECT " & vTable & ".* FROM " & vTable & " WHERE " &
vFld
> & " Like '" & sInitials & "*';", gCon, adOpenDynamic, adLockOptimistic

> 23    Set rs = db.OpenRecordset("SELECT " & vTable & ".* FROM " & vTable &
"
> WHERE " & vFld & " Like '" & sInitials & "*';", dbOpenSnapshot)

> 24   'If rsADO.EOF Then
> 25    If rs.EOF Then
> 26      AutoID = sInitials & "000001"
> 27    Else

> 28+   Rest of routine to generate unique number/key/name...



Mon, 15 Apr 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Can anyone explain why this happens?

2. Can somebody please explain the following:

3. Can someone PLEASE explain this simple thing?

4. Can someone explain this code for me please?

5. Please can someone explain what this error is

6. Hello, could someone please explain to me..

7. Could someone please explain In Process Servers?

8. Someone explain VB class reasoning to me, please...

9. Could someone please explain this line of code?

10. Please can someone explain what this error is

11. Please can someone explain what this error is

12. Can someone please explain connect strings....?

 

 
Powered by phpBB® Forum Software