My apologies. I am a little rusty to the forums.
The highlighted portion of the after update combobox function:
Code:
Private Sub cboComponent_AfterUpdate()
Dim strPN As String
'Replace drawing number with Primary part if the entry is a drawing
strPN = Nz(DLookup("Primary", "DRAWINGS", "Drawing='" & Me.cboComponent & "'"), "")
'If the string is not empty
If strPN <> "" Then
'this is a DRAWING, set component value and corresponding information
Me.txtComponent = Nz(DLookup("Primary", "DRAWINGS", "Drawing='" & Me.cboComponent & "'"), "")
Me.txtDescription = DLookup("Description", "PDatabase", "[PartNumber] = '" & Me.txtComponent & "'")
Me.txtUOM = DLookup("PurchaseUOM", "PDatabase", "[PartNumber] = '" & Me.txtComponent & "'")
Me.txtCageCode = DLookup("CageCodeA", "Drawings", "[Drawing] = '" & Me.cboComponent & "'")
Me.txtCageCodeA = DLookup("CageCodeB", "Drawings", "[Drawing] = '" & Me.cboComponent & "'")
Me.txtCageCodeB = DLookup("CageCodeC", "Drawings", "[Drawing] = '" & Me.cboComponent & "'")
Me.txtCageCodeC = DLookup("CageCodeD", "Drawings", "[Drawing] = '" & Me.cboComponent & "'")
Me.Revision = DLookup("Revision", "Drawings", "[Drawing] = '" & Me.cboComponent & "'")
'Load AlternateA into the drop down
On Error Resume Next
txtAlternateA.RowSource = "SELECT DRAWINGS.AlternateA " & _
"FROM DRAWINGS " & _
"WHERE DRAWINGS.Primary = '" & Me.txtComponent & "' " & _
"ORDER BY DRAWINGS.AlternateA; "
'Load AlternateB into the drop down
On Error Resume Next
txtAlternateB.RowSource = "Select DRAWINGS.AlternateB " & _
"FROM DRAWINGS " & _
"WHERE DRAWINGS.Primary = '" & Me.txtComponent & "' " & _
"ORDER BY DRAWINGS.AlternateB;"
'Load AlternateC into the drop down
On Error Resume Next
txtAlternateC.RowSource = "Select DRAWINGS.AlternateC " & _
"FROM DRAWINGS " & _
"WHERE DRAWINGS.Primary = '" & Me.txtComponent & "' " & _
"ORDER BY DRAWINGS.AlternateC;"
'If this is not a drawing, its an assembly/kit or regular part with possible alternates
ElseIf strPN = "" Then
'Compare entry to assembly and kit numbers in the table
strPN = Nz(DLookup("AssemblyKitNumber", "ASSEMBLIESKITS", "[AssemblyKitNumber]='" & Me.cboComponent & "'"), "")
'If a match is found
If strPN <> "" Then
'this is an assembly or kit
Me.txtComponent = strPN
Me.txtDescription = DLookup("Description", "ASSEMBLIESKITS", "[AssemblyKitNumber] ='" & Me.txtComponent & "'")
Me.txtUOM = DLookup("UOM", "ASSEMBLIESKITS", "[AssemblyKitNumber] ='" & Me.txtComponent & "'")
'Load all parts for possible alternates in drop down
txtAlternateA.RowSource = "SELECT PDatabase.PartNumber " & _
"FROM PDatabase " & _
"ORDER BY PDatabase.PartNumber; "
txtAlternateB.RowSource = "SELECT PDatabase.PartNumber " & _
"FROM PDatabase " & _
"ORDER BY PDatabase.PartNumber; "
txtAlternateC.RowSource = "SELECT PDatabase.PartNumber " & _
"FROM PDatabase " & _
"ORDER BY PDatabase.PartNumber; "
Else
'This is a part number
Me.txtComponent = Me.cboComponent
Me.txtDescription = DLookup("Description", "PDatabase", "[PartNumber] = '" & Me.txtComponent & "'")
Me.txtUOM = DLookup("PurchaseUOM", "PDatabase", "[PartNumber] = '" & Me.txtComponent & "'")
strPN = Nz(DLookup("AlternateA", "ALTERNATES", "[PartNumber]='" & Me.txtComponent & "'"), "")
If strPN <> "" Then
txtAlternateA.RowSource = "SELECT ALTERNATES.AlternateA " & _
"FROM ALTERNATES " & _
"WHERE ALTERNATES.PartNumber = '" & Me.txtComponent & "' " & _
"ORDER BY ALTERNATES.AlternateA; "
Else
txtAlternateA.RowSource = "SELECT PDatabase.PartNumber " & _
"FROM PDatabase " & _
"ORDER BY PDatabase.PartNumber; "
End If
strPN = Nz(DLookup("AlternateB", "ALTERNATES", "[PartNumber]='" & Me.txtComponent & "'"), "")
If strPN <> "" Then
txtAlternateA.RowSource = "SELECT ALTERNATES.AlternateB " & _
"FROM ALTERNATES " & _
"WHERE ALTERNATES.PartNumber = '" & Me.txtComponent & "' " & _
"ORDER BY ALTERNATES.AlternateB; "
Else
txtAlternateB.RowSource = "SELECT PDatabase.PartNumber " & _
"FROM PDatabase " & _
"ORDER BY PDatabase.PartNumber; "
End If
strPN = Nz(DLookup("AlternateC", "ALTERNATES", "[PartNumber]='" & Me.txtComponent & "'"), "")
If strPN <> "" Then
txtAlternateC.RowSource = "SELECT ALTERNATES.AlternateC " & _
"FROM ALTERNATES " & _
"WHERE ALTERNATES.PartNumber = '" & Me.txtComponent & "' " & _
"ORDER BY ALTERNATES.AlternateC; "
Else
txtAlternateC.RowSource = "SELECT PDatabase.PartNumber " & _
"FROM PDatabase " & _
"ORDER BY PDatabase.PartNumber; "
End If
End If
End If
End Sub
My add function:
Code:
Private Sub butAdd_Click()
'Add entry to list
'Insert vs Update options
'If the part is not in the list
If Me.ID.Tag & "" = "" Then
'add the part to the list
'Add main part
CurrentDb.Execute "INSERT INTO BOM(Assembly, Component, Description, AssemblyQty, UOM, CageCode) " & _
" VALUES ('" & Me.txtAssembly & "','" & Me.txtComponent & "','" & Me.txtDescription & "','" & Me.numAssemblyQty & "','" & Me.txtUOM & "','" & _
Me.txtCageCode & "')"
'If there is an AlternateA, Add AlternateA
If Not (Me.txtAlternateA & "" = "" And Me.txtCageCodeA & "" = "") Then
CurrentDb.Execute "INSERT INTO BOM(Component, Description, UOM, CageCode) " & _
" VALUES ('" & Me.txtAlternateA & "','" & Me.txtAltADescription & " \ALT" & "','" & Me.txtAltAUOM & "','" & Me.txtCageCodeA & "')"
End If
'If there is an AlternateB, Add AlternateB
If Not (Me.txtAlternateB & "" = "" And Me.txtCageCodeB & "" = "") Then
CurrentDb.Execute "INSERT INTO BOM(Component, Description, UOM, CageCode) " & _
" VALUES ('" & Me.txtAlternateB & "','" & Me.txtAltBDescription & " \ALT" & "','" & Me.txtAltBUOM & "','" & Me.txtCageCodeB & "')"
End If
'If there is an AlternateC, Add AlternateC
If Not (Me.txtAlternateC & "" = "" And Me.txtCageCodeC & "" = "") Then
CurrentDb.Execute "INSERT INTO BOM(Component, Description, UOM, CageCode) " & _
" VALUES ('" & Me.txtAlternateC & "','" & Me.txtAltCDescription & " \ALT" & "','" & Me.txtAltCUOM & "','" & Me.txtCageCodeC & "')"
End If
Me.numAssemblyQty.SetFocus
'update an already existing part
ElseIf InStr(Me.txtDescription, " \ALT") > 0 Then
CurrentDb.Execute "UPDATE BOM " & _
" SET Component='" & Me.txtComponent & "'" & _
", Description='" & Me.txtDescription & "'" & _
", UOM='" & Me.txtUOM & "'" & _
", CageCode='" & Me.txtCageCode & "'" & _
" WHERE ID=" & Me.frmEntrySub.Form.ID
Else
CurrentDb.Execute "UPDATE BOM " & _
" SET Assembly='" & Me.txtAssembly & "'" & _
", Component='" & Me.txtComponent & "'" & _
", Description='" & Me.txtDescription & "'" & _
", AssemblyQty='" & Me.numAssemblyQty & "'" & _
", UOM='" & Me.txtUOM & "'" & _
", CageCode='" & Me.txtCageCode & "'" & _
" WHERE ID=" & Me.frmEntrySub.Form.ID
End If
'Clear form after add/update
butClear_Click
'Refresh form
frmEntrySub.Form.Requery
End Sub
Screenshots:
What happens when I look up a drawing number now:
What happens when I add the drawing's record information A.K.A parts associated with that drawing:
What I would like my lookup to do now (I did this manually, so don't worry about the beginning of the descriptions, just the REF part):
I need the drawing number concatenated in the description (very similar to the concatenation of " \ALT" in my alternates description in my add function) is because after the records have been added to my BOM table, I export this table to an Excel. I am willing to do this in a report, as long as I can export it to an excel, where it will be copied and pasted into our standard Bill of Materials template. One of my Export functions is this:
I am looking at the first check box. I see "MOST" formatting, but this is not possible for what I need? I notice that when I mess with the manual formatting in the ribbon menu, my the formatting is applied to my entire table, headers and all. Is this why conditional formatting doesn't work on tables?