Visual Basic Q&A

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘format’

PRB: Error Setting Field Format Property of Access Tables

Symptoms
From Visual Basic, when trying to specify a field Format property of anAccess table (for example, field type DateTime) from blank to “Long Date”format, the following error occurs:

Run-time error ‘3421′:
Data type conversion error.
Resolution
The property data type constant should always be “dbText.” If other datatype constants, such as dbDate or dbNumeric are specified, you willencounter the error described above.

PRB: CompactDatabase Method Requires Locale to Convert 2.0 MDB

Symptoms
When attempting to use the Data Access Object (DAO) 3.5 CompactDatabasemethod to convert a Jet 2.0 .mdb file to a Jet 3.0 file format, theresulting .mdb file is still in a Jet 2.0 file format.
Resolution
DAO 3.5 requires you to provide explicitly the locale argument of theCompactDatabase when converting .mdb file formats.

How To Use ADO to Access Objects Through an ADSI LDAP Provider

Symptoms
The Active Directory Service Interfaces (ADSI) LightweightDirectory Access Protocol (LDAP) provider implements OLE DB interfaces thatallow you to use ActiveX Data Objects (ADO) to access objects in LDAPcompliant directories. You must create an ADO connection object and set itsProvider property to “ADsDSOObject”.You can specify any string, including”", as the connection string (first argument) of the ADO connectionobject’s open method.
The connection object Execute method’s CommandText (first object) is anLDAP query composed of four elements separated by semicolons, in thefollowing format:

<LDAP://server/adsidn>;ldapfilter;attributescsv;scope where:
server is the name (or IP address) of the server hosting the directory.adsidn is the distinguished name (DN) of the starting point for yourquery expressed ADsPath format with “/” separators and the root of thenamespace to the left. You can also use an X.500 style attributed nameformat with the relative distinguished names separated by commas and theroot of the name space to the right.1dap filter is the LDAP filter string (see rfc2254).attributescsv is a comma separated list of names of the attributes to be returned for each row in the recordset.scope is either: base, onelevel, or subtree.NOTE: rfc2253 specifies the LDAP syntaxes on which the ADSI LDAP syntax is based.
To return the ADsPath, class, and cn attributes of all the objects in allthe recipient containers in an Exchange server, you can use the followingCommandText (in URL format):

LDAP:<//server/o=organization/ou=site/cn=recipients>;(objectClass=*);ADsPath,objectClass,cn;subtree” or (in attributed name format):

<LDAP://server/cn=recipients,ou=site,o=organization>, _(objectClass=*);ADsPath,objectClass;subtree
Resolution
The following Visual Basic sample code illustrates this query:
Sample Code

Dim conn As ADODB.ConnectionDim rs As ADODB.RecordsetSet conn = New ADODB.Connectionconn.Provider = “ADSDSOObject”conn.Open “ADs Provider”Set rs = conn.Execute( _”<LDAP://server/o=organization/ou=site/cn=recipients>;” _& “(objectClass=*);ADsPath,objectClass,cn;subtree”)While Not rs.EOFDebug.Print rs.Fields(0).Value, rs.Fields(1).Value, _rs.Fields(2).Valuers.MoveNextWendconn.Close