| | |
|
|
|
Can anyone help me with DAO codes? |
| message from =?Utf-8?B?TGl6YQ==?= on 2 Jun 2004 |
I am not familiar with DAO. So far I am learning and writing ADO codes. I want to change it to ADO. I did but it is not working. Can anyone kindly with the below codes?
Original DAO codes
|
| Graham R Seach replied to =?Utf-8?B?TGl6YQ==?= on 3 Jun 2004 |
Liza,
I haven't put in any error handling, but I'm sure you can do that yourself.
Public Sub Schema(strTableName As String, strColumnName As String,
varKeyValue As Variant, strConnectionString As String)
Dim cn As ADODB.Connection
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim col As ADOX.Column
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set cat = New ADOX.Catalog
Set rs = New ADODB.Recordset
cn.ConnectionString = strConnectionString
cn.Open
cat.ActiveConnection = cn
rs.Open strTableName, cn, adOpenStatic, adLockReadOnly
Set tbl = cat.Tables(strTableName)
Set col = tbl.Columns(strColumnName)
Select Case col.Type
Case adInteger, adLongVarBinary, adCurrency, adSingle, adDouble,
adNumeric
rs.Find ("[" & strColumnName & "] = " & varKeyValue)
Case adDate
rs.Find ("[" & strColumnName & "] = #" & varKeyValue & "#")
Case adVarChar
rs.Find ("[" & strColumnName & "] = '" & varKeyValue & "'")
Case Else
MsgBox "ERROR: Invalid key field data type!"
GoTo Proc_Exit
End Select
If rs.EOF Then
MsgBox "Record not found"
Else
MsgBox rs(strColumnName).Name & " = " & rs(strColumnName).Value
End If
Proc_Exit:
rs.Close
Set rs = Nothing
Set col = Nothing
Set tbl = Nothing
Set cat = Nothing
cn.Close
Set cn = Nothing
Exit Sub
End Sub
Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
"Liza" <anonymous@discussions.microsoft.com> wrote in message
news:20E6A3AF-16FB-40A2-9FA2-51B582AEECB7@microsoft.com...
I want to change it to ADO. I did but it is not working. Can anyone kindly
with the below codes?
|
|
Archived message: Can anyone help me with DAO codes? (Microsoft Access Error Message)