Writing Data to Tags using VBA and FT View SE

AndJH

Member
Join Date
Jun 2013
Location
Pennsylvania
Posts
2
Hello everyone,
I'm having difficulty writing data to a TagGroup item in VBA. I'm pulling values from a SQL Express database and attempting to write the string value to a string tag. I'm new to VBA and FT View SE, and any help would be greatly appreciated. The problem lies in writing the variable PLCTestTag value to the TagGroup.Item object.

The code I am working with:

Code:
Public MyTagGroup As TagGroup

Private Sub Display_AnimationStart()        'Creates tag group on display load to build object and put into scan

If MyTagGroup Is Nothing Then       'Checks for existence of tag group
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName, 500)

MyTagGroup.Add "{[PLC]PALLET_ID[0]}"
End If

End Sub

Private Sub btnLookup_Released()

'Declare variables
Set objMyConn = New ADODB.Connection
Set objMyCmd = New ADODB.Command
Set objMyRecordSet = New ADODB.Recordset
Dim PLCTestTag As String

'Open Connection
objMyConn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=user;Initial Catalog=PALTAG;Data Source=USER-PC\SQLEXPRESS"
objMyConn.Open

'Set and Excecute SQL Command
Set objMyCmd.ActiveConnection = objMyConn
objMyCmd.CommandText = "Select SKUMASTER.UCC From SKUMASTER"
objMyCmd.CommandType = adCmdText
objMyCmd.Execute

'Open Recordset
Set objMyRecordSet.ActiveConnection = objMyConn
objMyRecordSet.Open objMyCmd

'Copy Data to Tags
PLCTestTag = objMyRecordSet.GetString(adClipString)
MyTagGroup.Item("{[PLC]PALLET_ID[0]}") = PLCTestTag

'Close Connection
objMyConn.Close


End Sub
 
Update

Found my error and corrected it. Code would appear to work if I wasn't getting the error: "Failed to resolve item's ID '/HMI::[PLC]VBA_TEST' because it does not exist on any server.

If anyone could shed some light on this it would be appreciated. I will update if I figure it out for other's benefit.

Code:
Public MyTagGroup As TagGroup

Public Sub Display_AnimationStart()        'Creates tag group on display load to build object and put into scan
'On Error GoTo ErrorTrap

If MyTagGroup Is Nothing Then       'Checks for existence of tag group
Set MyTagGroup = Application.CreateTagGroup(Me.AreaName, 500)

MyTagGroup.Add "{[PLC]VBA_TEST}"
End If

End Sub

Private Sub btnLookup_Released()

'Declare variables
Set objMyConn = New ADODB.Connection
Set objMyCmd = New ADODB.Command
Set objMyRecordSet = New ADODB.Recordset
Dim PLCTestTag As String
Dim PLCTestTagValue As Tag

'Open Connection
objMyConn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=user;Initial Catalog=PALTAG;Data Source=USER-PC\SQLEXPRESS"
objMyConn.Open

'Set and Excecute SQL Command
Set objMyCmd.ActiveConnection = objMyConn
objMyCmd.CommandText = "Select SKUMASTER.UCC From SKUMASTER"
objMyCmd.CommandType = adCmdText
objMyCmd.Execute

'Open Recordset
Set objMyRecordSet.ActiveConnection = objMyConn
objMyRecordSet.Open objMyCmd

'Copy Data to Tags
Set PLCTestTagValue = MyTagGroup.Item("{[PLC]VBA_TEST}")
PLCTestTag = objMyRecordSet.GetString(adClipString)
PLCTestTagValue.UserData = PLCTestTag

'Close Connection
objMyConn.Close


End Sub
 

Similar Topics

Hello, I am trying to send a keyboard command to a pc (press the letter "Y" followed by "Enter". I am modifying existing code which just sends a...
Replies
7
Views
2,568
Hi again guys, This forum has been great for all the questions ive asked these last few days. Another one now.. haha I am currently working...
Replies
3
Views
4,191
Hi friends, I m new to plc programming and i don't know how to write data block in boolean method. I m needed to write data block to...
Replies
0
Views
1,686
Hello everyone. My question is about moving data into selective bits in Controllogix. I want to move a hex value into the last word(bits 16-31) of...
Replies
3
Views
1,455
I have a third party application designed in vb that is reading/writing data to an AB SLC 5/05. I am unable to write more than 80 words of data to...
Replies
0
Views
1,450
Back
Top Bottom