Re: Connecting to a SQL Server 2005 using VBA and ADO

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Any reason you don't leave the code as you have?

The code example you have should work just fine....

dao should work just fine....

if that table is linked, then your code should work as is.

I would not use find first in this case, but perhaps you have reason for
doing so.....

I would have used:

dim rst as dao.RecordSet

set rst = currentdb.openrecordset("select * from contacts where contactid =
12345")

if rst.RecordCount > 0 then
'....do whatever....

end if

the above will work if you using linked tables to a back end mdb, or if your
tables are linked to sql server...the code does not need to be changed in
the above example when using sql server, or a plan Jane un-split database,
or a split database.

The above code will work fine for all 3 cases..and should not need to be
modified.....

I would not use findfirst even when not using sql server unless the data set
was small, and you had to repeat use findfirst a number of times. It is
generally better to just fetch the one record as a above then doing a table
scan with findfirst...

Also, I used dao.RecordSet, but if you don't have a reference to ado, then
your use of "RecordSet" should work just fine also...


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@xxxxxxx


.



Relevant Pages

  • Re: Jet to SQL conversion- What is equivalent ot "FindFirst" in a recordset?
    ... Back end tables upsized to Microsoft SQL Server 2000 Desktop Engine. ... "findfirst" line, ... I see no reason as to what ... and NOT use a adp project. ...
    (microsoft.public.access.forms)
  • Re: Update string too long?
    ... > And we won't question to reason for this routine as you asked... ... Pro SQL Server 2000 Database Design - ... > support the full length of the inserted data? ...
    (microsoft.public.sqlserver.programming)
  • RE: Identity/Seed Values
    ... is not a substitute for this. ... SQL Server doesn't change the IDENTITY value ... IDENTITY yourself except by deleting and then inserting a row (another reason ... why you shouldn't tie external meaning to an arbitrary IDENTITY value). ...
    (microsoft.public.sqlserver.programming)
  • Re: SQL 2005 Password Expiration
    ... New error codes ... Reason: Password change failed. ... password does not meet policy requirements because it is too short. ... Mike Epprecht, Microsoft SQL Server MVP ...
    (microsoft.public.sqlserver.security)
  • Re: Different results in SQL and Access
    ... This suggests a reason why you are getting different results. ... in MS-Access, with a table Linked to the SQL Server table, I get the ... This email account is my spam trap so I ...
    (microsoft.public.access.queries)