|
-
Oct 26th, 2006, 05:35 PM
#1
Thread Starter
New Member
Using VB to connect to MS Access
The following code runs as compiled code outside of MS Access. I'm trying to filter a recordset on the Access form. I can get a handle to the form object as an AccessObject, but when I try to set the object to an Access Form object I get an Error 13, Type Mismatch. I can retrieve a filtered recordset, but I can't apply this to the current recordset of the form. Any help would be greatly appreciated. The whole VB project can be emailed for debugging if that would help.
Thanks!
Public Sub FindRecord()
Dim access_app As Access.Application
Dim db As CurrentProject
Dim cnn1 As New ADODB.Connection
Dim comm As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim rs_filtered As New ADODB.Recordset
Dim rs_temp As New ADODB.Recordset
Dim db_name As String
Dim obj As AccessObject
Dim frm_obj As AccessObject
Dim frm As Access.Form
Dim frm_coll As Collection
Dim frm_name As String
Dim ndx As Long
Dim cnt As Long
Dim frm_title As String
Dim str As String
Dim SPN_txt As String
Dim prop As Property
SPN_txt = "235128301001"
frm_name = "f_Parcels"
Set access_app = Application
Set db = access_app.CurrentProject
db_name = db.Name
MsgBox "The open database is " & db_name
For Each obj In db.AllForms
'MsgBox "The object name is " & obj.Name
If obj.Name = frm_name Then
MsgBox "The desired object name is " & obj.Name
Set frm_obj = obj
Exit For
End If
Next
'-------------------------------------------------
'This is where the type mismatch happens
Set frm = frm_obj
frm_title = frm.Name
MsgBox "The title of the form is " & frm_title
'--------------------------------------------------
Set cnn1 = DataEnvironment1.Connection_parcel
Set comm = DataEnvironment1.Commands("parcel_att")
'MsgBox "cnn1 state: " & GetState(cnn1.State)
Set rs = comm.Execute
Set rs_temp = rs
rs_temp.Filter = "SPN = '" & SPN_txt & "'"
Set rs_filtered = rs_temp
cnt = rs_filtered.RecordCount
MsgBox "The filtered record count is " & cnt
End Sub
-
Oct 26th, 2006, 07:36 PM
#2
Fanatic Member
Re: Using VB to connect to MS Access
Welcome to the forums TedW
-
Oct 27th, 2006, 02:24 AM
#3
Hyperactive Member
Re: Using VB to connect to MS Access
 Originally Posted by TedW
'-------------------------------------------------
'This is where the type mismatch happens
Set frm = frm_obj
frm_title = frm.Name
MsgBox "The title of the form is " & frm_title
'--------------------------------------------------
Try this
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|