Amazing1984
New Member
- Joined
- Jun 28, 2010
- Messages
- 14
Ok I am trying to create a subrouting for the the node that is highlited in RED Color. I would like to delete that from this program but put it in seprate function and call it whenever i need to.
Please Help
Thank you
Please Help
Thank you
Code:
Public Function GetSub(strSubId As String)
Dim strSQL As String
Dim rsDeviceNumber As DAO.Recordset
Dim rsCymSubrel As DAO.Recordset
Dim Value As Integer, Valuey As Integer
'Dim rsX As DAO.Recordset
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM TblComponents WHERE ComponentId Like '" & strSubId & "*'"
DoCmd.RunSQL "DELETE * FROM TblNodes"
DoCmd.SetWarnings True
strSQL = "SELECT CYMTRANSFORMER.DeviceNumber, CYMTRANSFORMER.NetworkId, CYMTRANSFORMER.EquipmentId, CYMEQTRANSFORMER.NominalRatingKVA, CYMEQTRANSFORMER.PrimaryVoltageKVLL, CYMEQTRANSFORMER.SecondaryVoltageKVLL, CYMSECTIONDEVICE.DeviceType, CYMSECTIONDEVICE.Location, CYMSECTION.SectionId, CYMSECTION.FromNodeId, CYMNODE.X, CYMNODE.Y, CYMSECTION.ToNodeId, CYMNODE_1.X, CYMNODE_1.Y"
strSQL = strSQL & " FROM ((((CYMTRANSFORMER INNER JOIN CYMSECTIONDEVICE ON CYMTRANSFORMER.DeviceNumber = CYMSECTIONDEVICE.DeviceNumber)" _
& " INNER JOIN CYMSECTION ON CYMSECTIONDEVICE.SectionId = CYMSECTION.SectionId)" _
& " INNER JOIN CYMNODE ON CYMSECTION.FromNodeId = CYMNODE.NodeId) INNER JOIN CYMNODE AS CYMNODE_1 ON CYMSECTION.ToNodeId = CYMNODE_1.NodeId)" _
& " INNER JOIN CYMEQTRANSFORMER ON CYMTRANSFORMER.EquipmentId = CYMEQTRANSFORMER.EquipmentId"
strSQL = strSQL & " WHERE (((CYMTRANSFORMER.NetworkId) Like '" & strSubId & "*'));"
Set rsDeviceNumber = mdbCymdistSubrel.OpenRecordset(strSQL)
Set rsCymSubrel = mdbCymdistSubrel.OpenRecordset("TblComponents")
'Set rsX = rsDeviceNumber
rsDeviceNumber.MoveFirst
Do Until rsDeviceNumber.EOF
Debug.Print rsDeviceNumber!DeviceNumber, rsDeviceNumber!FromNodeId, rsDeviceNumber![CYMNODE.X], rsDeviceNumber![CYMNODE.Y], rsDeviceNumber!ToNodeId, rsDeviceNumber![CYMNODE_1.X], rsDeviceNumber![CYMNODE_1.Y]
' Value = FromNode()
' Valuey = ToNode()
[COLOR=red]Dim rsTblNodes As DAO.Recordset[/COLOR]
[COLOR=red]Dim lngFromNodeId As Long, lngToNodeId As Long[/COLOR]
[COLOR=red]Set rsTblNodes = mdbCymdistSubrel.OpenRecordset("TblNodes")[/COLOR]
[COLOR=red]rsTblNodes.FindFirst "NodeName = '" & rsDeviceNumber!FromNodeId & "'"[/COLOR]
[COLOR=red]If rsTblNodes.NoMatch Then[/COLOR]
[COLOR=red] rsTblNodes.AddNew[/COLOR]
[COLOR=red] rsTblNodes!NodeName = rsDeviceNumber!FromNodeId[/COLOR]
[COLOR=red] rsTblNodes!X = rsDeviceNumber![CYMNODE.X][/COLOR]
[COLOR=red] rsTblNodes!Y = rsDeviceNumber![CYMNODE.Y][/COLOR]
[COLOR=red] lngFromNodeId = rsTblNodes!nodeid[/COLOR]
[COLOR=red] rsTblNodes.Update[/COLOR]
[COLOR=red]Else[/COLOR]
[COLOR=red] lngFromNodeId = rsTblNodes!nodeid[/COLOR]
[COLOR=red]End If[/COLOR]
[COLOR=red]rsTblNodes.FindFirst "NodeName = '" & rsDeviceNumber!ToNodeId & "'"[/COLOR]
[COLOR=red]If rsTblNodes.NoMatch Then[/COLOR]
[COLOR=red] rsTblNodes.AddNew[/COLOR]
[COLOR=red] rsTblNodes!NodeName = rsDeviceNumber!ToNodeId[/COLOR]
[COLOR=red] rsTblNodes!X = rsDeviceNumber![CYMNODE_1.X][/COLOR]
[COLOR=red] rsTblNodes!Y = rsDeviceNumber![CYMNODE_1.Y][/COLOR]
[COLOR=red] lngToNodeId = rsTblNodes!nodeid[/COLOR]
[COLOR=red] rsTblNodes.Update[/COLOR]
[COLOR=red]Else[/COLOR]
[COLOR=red] lngToNodeId = rsTblNodes!nodeid[/COLOR]
[COLOR=red]End If[/COLOR]
rsCymSubrel.AddNew
rsCymSubrel!ComponentId = Trim(rsDeviceNumber!DeviceNumber)
rsCymSubrel!ComponentTypeId = 2
rsCymSubrel!FromNode = lngFromNodeId
rsCymSubrel!ToNode = lngToNodeId
rsCymSubrel.Update
rsDeviceNumber.MoveNext
Loop
End Function