By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,012 Members | 1,235 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,012 IT Pros & Developers. It's quick & easy.

Reading, writing and deleting records in access database, PLease help

P: 1
I'm a total amateur to VBS but need help on a VBS script. This is used in a HMI system from Siemens called WinCC, used for process viewing and control.

What I need to is to write to a table in Access, then read these values and then delete records (rows) in Access.
By using help functions in WinCC I have this set up:

I created an Access database with the WINCC_DATA table and columns (ID,
TagValue) with the ID as the Auto Value.

Then I can write to Access by the following code:

Dim objConnection
Dim strConnectionString
Dim lngValue
Dim strSQL
Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=SampleDSN;UID=;PWD=;"
lngValue = HMIRuntime.Tags("Tag1").Read
strSQL = "INSERT INTO WINCC_DATA (TagValue) VALUES (" & lngValue & ");"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
Set objCommand = CreateObject("ADODB.Command")
With objCommand
.ActiveConnection = objConnection
.CommandText = strSQL
End With
Set objCommand = Nothing
Set objConnection = Nothing

This actually works fine, pure luck I guess!

Can anyone help me with scripts for:
1. Reading one record (row) according to a ID number
2. Deleting the a record (row) according to a ID number

I would be very thankful for any help!

Best regards
Aug 26 '06 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,418
You can also use SQL statements to do this:

SQL= "DELETE Current.ID FROM [Current] WHERE (((Current.ID)="+str(my_value)+"));"

To view the information or edit information in VB is this kind of code:

Dim myr As Recordset
Dim mydb As Database
Set mydb = CurrentDb()
Set myr = mydb.OpenRecordset("Local_STRUCTURES1")

myr.AddNew 'adds new record programaticcly
myr("[STRUCTURE]") = "fdfdf"
myr("[Description]") = "MARK"

myr.Edit 'Edits new record programaticcly
myr("[STRUCTURE]") = "fdff"
myr("[Description]") = "MARK"

result = myr("[STRUCTURE]") 'gets an information and gives it to a variable

Aug 29 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.