Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 26th, 2006, 01:01 PM
Registered User
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reading, Writing and deleting access record, Help!

Hia!
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
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
With objCommand
.ActiveConnection = objConnection
.CommandText = strSQL
End With
objCommand.Execute
Set objCommand = Nothing
objConnection.Close
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
Vadar


 
Old August 28th, 2006, 06:36 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

The two scripts you want will work pretty much the same way. How will the user select the ID Number? The ID number should not be meaningful data to the user. Is there another way they would look up data?

Also, where do you want them to get the output? In an Access report, or in a message box from the script? Have you considered using an HTA interface?

Lemme know.


mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating, Writing to and Deleting Text Files goels Access VBA 7 January 30th, 2007 11:51 AM
Writing works then reading fails childoftv XSLT 3 April 22nd, 2006 04:09 AM
Reading from a xml file and writing to another billy_bob_the_3rd XML 5 April 29th, 2005 01:40 PM
Reading / Writing from Serial Port ashu_from_india General .NET 1 April 29th, 2005 03:50 AM
Reading and Writing Objects Capi JSP Basics 2 July 29th, 2003 03:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.