Create Sub-Routine for the following program.

Status
Not open for further replies.

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


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()
Dim rsTblNodes As DAO.Recordset
Dim lngFromNodeId As Long, lngToNodeId As Long
Set rsTblNodes = mdbCymdistSubrel.OpenRecordset("TblNodes")
rsTblNodes.FindFirst "NodeName = '" & rsDeviceNumber!FromNodeId & "'"
If rsTblNodes.NoMatch Then
rsTblNodes.AddNew
rsTblNodes!NodeName = rsDeviceNumber!FromNodeId
rsTblNodes!X = rsDeviceNumber![CYMNODE.X]
rsTblNodes!Y = rsDeviceNumber![CYMNODE.Y]
lngFromNodeId = rsTblNodes!nodeid
rsTblNodes.Update
Else
lngFromNodeId = rsTblNodes!nodeid
End If
rsTblNodes.FindFirst "NodeName = '" & rsDeviceNumber!ToNodeId & "'"
If rsTblNodes.NoMatch Then
rsTblNodes.AddNew
rsTblNodes!NodeName = rsDeviceNumber!ToNodeId
rsTblNodes!X = rsDeviceNumber![CYMNODE_1.X]
rsTblNodes!Y = rsDeviceNumber![CYMNODE_1.Y]
lngToNodeId = rsTblNodes!nodeid
rsTblNodes.Update
Else
lngToNodeId = rsTblNodes!nodeid
End If
rsCymSubrel.AddNew
rsCymSubrel!ComponentId = Trim(rsDeviceNumber!DeviceNumber)
rsCymSubrel!ComponentTypeId = 2
rsCymSubrel!FromNode = lngFromNodeId
rsCymSubrel!ToNode = lngToNodeId
rsCymSubrel.Update


rsDeviceNumber.MoveNext
Loop
End Function
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Status
Not open for further replies.

Forum statistics

Threads
1,225,521
Messages
6,185,458
Members
453,293
Latest member
zhangjiayi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top