Is the form bound to a DAO or ADO recordset?

A

Alejandro Mesa

Hello!

Is there a way to know if a form is bound to a DAO recordset or an ADO
recordset?


Thanks in advance,


AMB
 
A

Alejandro Mesa

Cheryl,

Thanks for the links, both are very helpful.

In my case (mdb), I am setting the form's recordset property directly, sometimes with a DAO others with an ADO recordset. I got stuck when trying to implement a function to sort the recordset bound to the form. This procedure use Form.RecordsetClone in order to get a clone of the recordset bound to the form but because DAO and ADO implement the Sort property in different way, I need to know what kind it is in order to continue.

Example:

private sortCol as string
private sortDir as string

private sub SortRst(colName as string)
dim rst as object

if sortCol <> colName then
sortCol = colName
sortDir = "ASC"
else
if sortDir = "ASC" then
sortDir = "DESC"
else
sortDir = "ASC"
end if
end if

set rst = me.recordsetClone

rst.Sort = colName & " " & sortDir

if rst is ADO then
set me.recordset = rst
else
set me.recordset = rst.OpenRecordset
endif

set rst = nothing
end sub



Regards,

AMB
 
A

Alex Dybenko

Hi,
you can use TypeOf:

If TypeOf rst Is DAO.Recordset Then
'DAO
else
'ado
end if

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com


Cheryl,

Thanks for the links, both are very helpful.

In my case (mdb), I am setting the form's recordset property directly,
sometimes with a DAO others with an ADO recordset. I got stuck when trying
to implement a function to sort the recordset bound to the form. This
procedure use Form.RecordsetClone in order to get a clone of the recordset
bound to the form but because DAO and ADO implement the Sort property in
different way, I need to know what kind it is in order to continue.

Example:

private sortCol as string
private sortDir as string

private sub SortRst(colName as string)
dim rst as object

if sortCol <> colName then
sortCol = colName
sortDir = "ASC"
else
if sortDir = "ASC" then
sortDir = "DESC"
else
sortDir = "ASC"
end if
end if

set rst = me.recordsetClone

rst.Sort = colName & " " & sortDir

if rst is ADO then
set me.recordset = rst
else
set me.recordset = rst.OpenRecordset
endif

set rst = nothing
end sub



Regards,

AMB
 

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

Top