How to import sting variable into table

  • Thread starter Thread starter jkoivula
  • Start date Start date
J

jkoivula

Hi!

I'm using DDE-link for getting data from another
application. DDE-link is working OK, but how can i
store value from string-variable to table?

Option Compare Database
Option Explicit

Function ReadDDE()
Dim Chan1 As Long
Dim Arvo1 As String

On Error Resume Next
Shell "C:\Mel\Meldde.exe", vbHide
Chan1 = DDEInitiate("Meldde", "Std")

Arvo1 = DDERequest(Chan1, "Y1")
DoCmd.OpenTable "Data", acNormal, acEdit
DoCmd.GoToRecord acTable, "Data", acNewRec

DoCmd.Close acTable, "Data"

If Err Then
MsgBox " VIRHE " & Err.Description
End If
DDETerminateAll
End Function

So i wan't to put the value from "Arvo1" to table "Data"
How can I do it?

Thanks beforehands!
 
Hi

if you add three more variables as follows:
dim cnn as ADODB.CONNECTION
DIM rs as adodb.recordset
dim strSQL as String

then after the line:
Arvo1 = DDERequest(Chan1, "Y1")

add the following:
set cnn = new adodb.connection
set rs = new adodb.recordset

set cnn = currentproject.connection

strSQL = "SELECT * FROM Data"

with rs

.activeconnection = cnn
.cursorType = adOpenKeyset
.locktype = adLockOptimistic
.Open strSQL,,,,adcmdText

.addnew
![FieldName] = Arvo1
.update

end with

rs.close
cnn.close

set rs = nothing
set cnn = nothing

This assumes that there is only one field in the table "Data". If there are
more fields, then add those fields in between the .addnew & .update lines
with the appropriate values. It also assumes that you have Access 2000 or
later

Amend FieldName to suit the actual Field Name.

Get rid of the DoCmd lines.

Hope this helps

Ross Petersen
 
Hi Ross.

Thanks for your advice. I managed to get this working also
with Access-97 (we actually still use that version). Here
is the current code:

Function Read()

Dim dbsOld As Database
Dim rstData As Recordset
Dim strLuku1 As String
Dim Chan1 As Long

On Error Resume Next
Shell "C:\Mel\Meldde.exe", vbHide
Chan1 = DDEInitiate("Meldde", "Std")

Set dbsOld = OpenDatabase
("C:\Tietokanta\Konetietokanta.mdb")
Set rstData = dbsOld.OpenRecordset("Data",
dbOpenDynaset)

strLuku1 = DDERequest(Chan1, "Y1")

With rstData
.AddNew
!Y1 = strLuku1
.Update
.Bookmark = .LastModified
End With


rstData.Close 'Close table
dbsOld.Close 'Close database

DDETerminateAll
End Function

Now i still have one question. I also tried this to other
direction (from access to logic). And quess what. No
success. Can you give me advice how to do that?

Jari
-----Original Message-----
Hi

if you add three more variables as follows:
dim cnn as ADODB.CONNECTION
DIM rs as adodb.recordset
dim strSQL as String

then after the line:
Arvo1 = DDERequest(Chan1, "Y1")

add the following:
set cnn = new adodb.connection
set rs = new adodb.recordset

set cnn = currentproject.connection

strSQL = "SELECT * FROM Data"

with rs

.activeconnection = cnn
.cursorType = adOpenKeyset
.locktype = adLockOptimistic
.Open strSQL,,,,adcmdText

.addnew
![FieldName] = Arvo1
.update

end with

rs.close
cnn.close

set rs = nothing
set cnn = nothing

This assumes that there is only one field in the table "Data". If there are
more fields, then add those fields in between the .addnew & .update lines
with the appropriate values. It also assumes that you have Access 2000 or
later

Amend FieldName to suit the actual Field Name.

Get rid of the DoCmd lines.

Hope this helps

Ross Petersen

jkoivula said:
Hi!

I'm using DDE-link for getting data from another
application. DDE-link is working OK, but how can i
store value from string-variable to table?

Option Compare Database
Option Explicit

Function ReadDDE()
Dim Chan1 As Long
Dim Arvo1 As String

On Error Resume Next
Shell "C:\Mel\Meldde.exe", vbHide
Chan1 = DDEInitiate("Meldde", "Std")

Arvo1 = DDERequest(Chan1, "Y1")
DoCmd.OpenTable "Data", acNormal, acEdit
DoCmd.GoToRecord acTable, "Data", acNewRec

DoCmd.Close acTable, "Data"

If Err Then
MsgBox " VIRHE " & Err.Description
End If
DDETerminateAll
End Function

So i wan't to put the value from "Arvo1" to table "Data"
How can I do it?

Thanks beforehands!
.
 
Back
Top