Sorry, I forgot to mention, the record is not being created in the lookup table. The lookup is being performed on a form, and the record is added to a different table, which is then exported upon completion.
So, the form contains the two fields mentioned above (combo boxes). Field1 has this rowsource:
Code:
SELECT [PDatabase].[PartNumber], [PDatabase].[Description], [PDatabase].[PurchaseUOM] FROM [PDatabase] ORDER BY [PartNumber] UNION SELECT [Drawing], Null, Null FROM [DRAWINGS] UNION SELECT [AssemblyKitNumber], Null, Null FROM [ASSEMBLIESKITS];
The following code occurs when Field1 is populated:
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
Revision.Requery
'Me.txtComponent = Nz(DLookup("Primary", "DRAWINGS", "[Drawing]=" & Me.cboComponent & " AND Revision ='" & Me.Revision & "'"), "")
'Me.txtDescription = DLookup("Description", "PDatabase", "[PartNumber] = '" & Me.txtComponent & "'")
'Me.txtUOM = DLookup("StockUOM", "PDatabase", "[PartNumber] = '" & Me.txtComponent & "'")
'Me.txtCageCode = DLookup("CageCodeA", "Drawings", "[Drawing] = " & Me.cboComponent & " AND Revision='" & Me.Revision & "'")
'Me.txtCageCodeA = DLookup("CageCodeB", "Drawings", "[Drawing] = " & Me.cboComponent & " AND Revision='" & Me.Revision & "'")
'Me.txtCageCodeB = DLookup("CageCodeC", "Drawings", "[Drawing] = " & Me.cboComponent & " AND Revision='" & Me.Revision & "'")
'Me.txtCageCodeC = DLookup("CageCodeD", "Drawings", "[Drawing] = " & Me.cboComponent & " AND Revision='" & Me.Revision & "'")
'
'
''Load AlternateA into the drop down
'On Error Resume Next
' txtAlternateA.RowSource = "SELECT DRAWINGS.AlternateA " & _
' "FROM DRAWINGS " & _
' "WHERE DRAWINGS.Drawing = " & Me.txtComponent & " AND Revision ='" & Me.Revision & "' " & _
' "ORDER BY DRAWINGS.AlternateA; "
' Me.txtAlternateA.BackColor = vbYellow
'
''Load AlternateB into the drop down
'On Error Resume Next
' txtAlternateB.RowSource = "Select DRAWINGS.AlternateB " & _
' "FROM DRAWINGS " & _
' "WHERE DRAWINGS.Drawing = " & Me.txtComponent & " AND Revision ='" & Me.Revision & "' " & _
' "ORDER BY DRAWINGS.AlternateB;"
' Me.txtAlternateB.BackColor = vbYellow
'
''Load AlternateC into the drop down
'On Error Resume Next
' txtAlternateC.RowSource = "Select DRAWINGS.AlternateC " & _
' "FROM DRAWINGS " & _
' "WHERE DRAWINGS.Drawing = " & Me.txtComponent & " AND Revision ='" & Me.Revision & "' " & _
' "ORDER BY DRAWINGS.AlternateC;"
' Me.txtAlternateC.BackColor = vbYellow
'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; "
If txtAlternateA.ListCount = 0 Then
txtAlternateA.BackColor = vbWhite
Else
Me.txtAlternateA.BackColor = vbYellow
End If
txtAlternateB.RowSource = "SELECT PDatabase.PartNumber " & _
"FROM PDatabase " & _
"ORDER BY PDatabase.PartNumber; "
If txtAlternateB.ListCount = 0 Then
txtAlternateB.BackColor = vbWhite
Else
Me.txtAlternateB.BackColor = vbYellow
End If
txtAlternateC.RowSource = "SELECT PDatabase.PartNumber " & _
"FROM PDatabase " & _
"ORDER BY PDatabase.PartNumber; "
If txtAlternateC.ListCount = 0 Then
txtAlternateC.BackColor = vbWhite
Else
Me.txtAlternateC.BackColor = vbYellow
End If
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; "
Me.txtAlternateA.BackColor = vbYellow
Else
txtAlternateA.RowSource = "SELECT PDatabase.PartNumber " & _
"FROM PDatabase " & _
"ORDER BY PDatabase.PartNumber; "
Me.txtAlternateA.BackColor = vbYellow
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; "
Me.txtAlternateA.BackColor = vbYellow
Else
txtAlternateB.RowSource = "SELECT PDatabase.PartNumber " & _
"FROM PDatabase " & _
"ORDER BY PDatabase.PartNumber; "
Me.txtAlternateB.BackColor = vbYellow
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; "
Me.txtAlternateC.BackColor = vbYellow
Else
txtAlternateC.RowSource = "SELECT PDatabase.PartNumber " & _
"FROM PDatabase " & _
"ORDER BY PDatabase.PartNumber; "
Me.txtAlternateC.BackColor = vbYellow
End If
End If
End If
End Sub
When Field2 has a selection (which it will not let me make a different selection):
Code:
Private Sub Revision_AfterUpdate()
Me.txtComponent = Nz(DLookup("Primary", "DRAWINGS", "[Drawing]='" & Me.cboComponent & "' AND [Revision] ='" & Me.Revision & "'"), "")
Me.txtDescription = DLookup("Description", "PDatabase", "[PartNumber] = '" & Me.txtComponent & "'")
Me.txtUOM = DLookup("StockUOM", "PDatabase", "[PartNumber] = '" & Me.txtComponent & "'")
Me.txtCageCode = Nz(DLookup("CageCodeA", "Drawings", "[Drawing] = " & Me.cboComponent & " AND Revision='" & Me.Revision & "'"), "")
Me.txtCageCodeA = DLookup("CageCodeB", "Drawings", "[Drawing] = " & Me.cboComponent & " AND Revision='" & Me.Revision & "'")
Me.txtCageCodeB = DLookup("CageCodeC", "Drawings", "[Drawing] = " & Me.cboComponent & " AND Revision='" & Me.Revision & "'")
Me.txtCageCodeC = DLookup("CageCodeD", "Drawings", "[Drawing] = " & Me.cboComponent & " AND Revision='" & Me.Revision & "'")
'Load AlternateA into the drop down
On Error Resume Next
txtAlternateA.RowSource = "SELECT DRAWINGS.AlternateA " & _
"FROM DRAWINGS " & _
"WHERE DRAWINGS.Drawing = " & Me.txtComponent & " AND Revision ='" & Me.Revision & "' " & _
"ORDER BY DRAWINGS.AlternateA; "
Me.txtAlternateA.BackColor = vbYellow
'Load AlternateB into the drop down
On Error Resume Next
txtAlternateB.RowSource = "Select DRAWINGS.AlternateB " & _
"FROM DRAWINGS " & _
"WHERE DRAWINGS.Drawing = " & Me.txtComponent & " AND Revision ='" & Me.Revision & "' " & _
"ORDER BY DRAWINGS.AlternateB;"
Me.txtAlternateB.BackColor = vbYellow
'Load AlternateC into the drop down
On Error Resume Next
txtAlternateC.RowSource = "Select DRAWINGS.AlternateC " & _
"FROM DRAWINGS " & _
"WHERE DRAWINGS.Drawing = " & Me.txtComponent & " AND Revision ='" & Me.Revision & "' " & _
"ORDER BY DRAWINGS.AlternateC;"
Me.txtAlternateC.BackColor = vbYellow
End Sub
It would take me all day to type up the whole structure, and theres a backend and frontend, so it would be very time consuming to take out sensitive data.
I can provide screenshots though
So, here's the DRAWING table structure:
Here's the form where entry/lookup takes place:
Here's where the Rev is selected (When I try to select B from the drop down, it pauses for a couple seconds, and then select Rev A by itself):
The remaining fields are coded to populate based on selections made in Field1 and Field2, but they do not.