| re: Searching multiple tables in Access using Visual Basic
Katrina wrote:[color=blue]
> I am trying to write a piece of code that will search through a number
> of different tables (current one being tableNm) to look for a specific
> street name that has been entered by the user and saved as
> Enteredstreet. If the street is found I then want to display a message
> box saying what table the street name is in. The code I am currently
> trying to use is this:
>
> Sub dbOpentableX()
>
> Dim dbsAddSampling As Database
> Dim rstTable As Recordset
>
> Set dbsAddSampling = CurrentDb
> Set rstTable = dbsAddSampling.OpenRecordset(tableNm)
>
> With rstTable
> .Index = "STREETNM"
>
> Do While Not .EOF
> If !STREETNM = Enteredstreet Then
> MsgBox "Street name found in" & tableNm
>
> Exit Do
>
> Else
> .MoveNext
>
> End If
>
> Loop
>
> End With
>
> End Sub
>
> But when I try to run this an error message comes up saying
> 'User-defined type not defined' and then highlights the bit of code
> saying 'dbsAddSampling As Database'. I have probably done something
> really stupid, or else the code is just rubbish, but I would
> appreciate any help.
>
> Katrina[/color]
You might try
If (CurrentProject.Connection.Execute( _
"SELECT * FROM tbl2002Transactions " _
& "WHERE fldDescription = """ & Description & """").BOF) Then
MsgBox Description & " not found"
Else
MsgBox Description & " found"
End If
substituting your own variables.
--
--
Lyle
--
From ADO28.chm
Deprecated Components
Each of the following components is considered obsolete. While these
components are still supported in this release of the Microsoft® Data
Access Components (MDAC), they may be removed in the future. When
writing new applications, you should avoid using these deprecated
components. When modifying existing applications, you are strongly
encouraged to remove any dependency on these components.
ODBC Provider (MSDASQL)
You are strongly encouraged to use one of the native OLE DB Providers
instead of the Microsoft Open Database Connectivity (ODBC) Provider.
Native OLE DB Providers provide better application stability and
performance. Furthermore, native OLE DB Providers will be supported in
the future, whereas MSDASQL will not have any new features added to it,
will not be available on 64-bit, and will not be accessible from the OLE
DB NET Data Provider.
Remote Data Services (RDS)
Remote Data Services (RDS) is a proprietary Microsoft mechanism for
accessing remote data across the Internet or intranet. Microsoft is now
shipping the Microsoft Simple Object Access Protocol (SOAP) Toolkit 2.0
that enables you to access remote data using an open, XML-based
standard. Given the availability of the SOAP Toolkit 2.0, you should
migrate from RDS to SOAP. The SOAP 2.0 Toolkit 2.0 also includes sample
code for remotely accessing Microsoft ActiveX® Data Objects (ADO)
Recordsets.
Jet and Replication Objects (JRO)
The Microsoft Jet OLE DB Provider and other related components were
removed from MDAC 2.6. Microsoft has deprecated the Microsoft Jet
Engine, and plans no new releases or service packs for this component.
As a result, the Jet and Replication Objects (JRO) is being deprecated
in this release and will not be available in any future MDAC releases.
..... |