Create Sub-Routine for the following program.

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

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
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,225,525
Messages
6,185,469
Members
453,296
Latest member
zashue22

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