Get data Collected from Macro to table

garryt1

New Member
Joined
Feb 12, 2003
Messages
16
Hi,

I am using a vba macro to import data from a plc, i now want to put this data from the plc into a table using the same macro.
Can anyone show me how this is carried out, i have done this in vb before using DAO 3.6 but it will not work correctly in vba.

regards,
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
DAO should work ok in Acces, but if you are using A2K or higer you will need to set a reference to it.

Peter
 
Upvote 0
Peter,

Thanks for the reply!
However i already have a reference set to DAO3.6 but still fails to work with message (type mismatch) on the following code
Set rstProcess1 = db.OpenRecordset("Process1", dbOpenTable)
I have declared rstProcess1 table as a recordset in the project.

regards,
 
Upvote 0
What you have looks OK, Can you post the rest of the code for us to look at please

Peter
 
Upvote 0
Explictly declare the recordset as a DAO.Recordset
Depending on the sequence of your references, the first listed might be ADO.

Code:
Dim dbs As DAO.Dataset
Dim rs As DAO.Recordset

Set dbs = CurrentDb()

Set rs = dbs.OpenRecordset("name", dbOpenTable)

As a preference, I have a habit of not using dbOpenTable. When using DAO, I prefer dbOpenSnapshot & dbOpenDynaset depending on whether I need to read/read+write.

Mike
 
Upvote 0
Peter,

Here is the code in my module,

Sub Word_Read()
Dim intData As Integer
Dim db As Database
Dim rstProcess As Recordset


Set db = OpenDatabase("C:\installs\db1.mdb")

With db
Set rstProcess = db.OpenRecordset("Process")

'open dde link: testsol=DDE Topic

RSIchan = DDEInitiate("RSLinx", "testsol")

'get data and store in data variable

Data = DDERequest(RSIchan, "N7:50")

'Paste data into selected range

intData = Data
'close dde link
With rstProcess
rstProcess.AddNew
rstProcess![intData] = intData
rstProcess.Update
rstProcess.Close
End With
db.Close

DDETerminate (RSIchan)

End With

End Sub




regards,
 
Upvote 0
What you have looks OK. Did you try Mike's suggestion? This will make a differnce if you are using A2K and above.

Dim db As DAO.Database
Dim rstProcess As DAO.Recordset

Peter
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,986
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top