Hey guys I am new to the forums and am trying to make the switch to access to make it easier for my electricians to know what happens when they work on a machine.
So I have a database that has all the machines currently connected to my electrical grid. Each machine has its own bar-code label in order to keep track of it and that is what I am using for the primary key. This is how I have my first table set up as:
Machine Bar-Code||Description||Location||Upstream
The upstream is the machine that is connected before it. Basically what I am trying to do is have a way for a report to be generated for a user with the connections that lead to the machine so if the machine needs to be taken down we know what else has to be taken down to work on it. I had a crude version of what I want in excel using VB code created by someone (before my time) that generates all the machines connected downstream and all the machines connected upstream of the bar-code you search for. Here is the vb code:
Code:
Sub findChildren()
Dim searchString As String 'string we're looking for
Dim foundString As String 'string we're comparing to the searchString
Dim searchRow As Integer 'row we're checking for a parent match
Dim writeRow As Integer 'row we just wrote the most recent parent to
Dim readRow As Integer 'row containing the "parent" we're looking for
Dim clearRow As Integer 'row to clear
searchRow = 2
writeRow = 3
'clear the result rows
clearRow = 3
While (Sheets("Form").Range("C" & clearRow) <> "")
Sheets("Form").Range("C" & clearRow) = ""
Sheets("Form").Range("D" & clearRow) = ""
Sheets("Form").Range("E" & clearRow) = ""
clearRow = clearRow + 1
Wend
searchString = Sheets("Form").Range("C" & searchRow)
While (searchString <> "")
readRow = 3
foundString = Sheets("RawData").Range("D" & readRow)
While (foundString <> "")
If (foundString = searchString) Then
Sheets("Form").Range("C" & writeRow) = Sheets("RawData").Range("D" & readRow)
Sheets("Form").Range("D" & writeRow) = Sheets("RawData").Range("B" & readRow)
Sheets("Form").Range("E" & writeRow) = Sheets("RawData").Range("C" & readRow)
writeRow = writeRow + 1
End If
readRow = readRow + 1
foundString = Sheets("RawData").Range("D" & readRow)
Wend
searchRow = searchRow + 1
searchString = Sheets("Form").Range("D" & searchRow)
Wend
End Sub
-------------------------------------------------------------------------------------------------
Sub findParents()
Dim searchString As String 'string we're looking for
Dim foundString As String 'string we're comparing to searchString
Dim searchRow As Integer 'row we're checking for a parent match
Dim writeRow As Integer 'row we just wrote to
Dim readRow As Integer 'row containing the child we're looking for the parent for
Dim parentFound As Boolean 'flag indicating we've found the parent
Dim parent As String
Dim clearRow As Integer
'clear the result rows
Sheets("Form").Range("I" & 2) = ""
Sheets("Form").Range("J" & 2) = ""
clearRow = 3
While (Sheets("Form").Range("H" & clearRow) <> "")
Sheets("Form").Range("H" & clearRow) = ""
Sheets("Form").Range("I" & clearRow) = ""
Sheets("Form").Range("J" & clearRow) = ""
clearRow = clearRow + 1
Wend
searchRow = 2
writeRow = 3
searchString = Sheets("Form").Range("H" & searchRow)
While (searchString <> "")
parentFound = False
readRow = 3
foundString = Sheets("RawData").Range("B" & readRow)
'first, find the load to identify its parent
While (foundString <> "" And parentFound = False)
If (foundString = searchString) Then
parent = Sheets("RawData").Range("D" & readRow)
Sheets("Form").Range("I" & searchRow) = Sheets("RawData").Range("D" & readRow)
Sheets("Form").Range("J" & searchRow) = Sheets("RawData").Range("C" & readRow)
Sheets("Form").Range("H" & writeRow) = Sheets("RawData").Range("D" & readRow)
parentFound = True
writeRow = writeRow + 1
End If
readRow = readRow + 1
foundString = Sheets("RawData").Range("B" & readRow)
Wend
searchRow = searchRow + 1
searchString = Sheets("Form").Range("H" & searchRow)
Wend
End Sub
My question is how can I implement this VB code to have a report be generated with the same results in Access to make it cleaner. Any ideas?? All help is appreciated!