I tried to manipulate some code that was based on making two selections and then looking up the third. Now I have just one item to select and want my database to provide a lookup. I took the code (pasted at the end for reference) and came up with this:
The code actually fires without bugs (which is a huge accomplishment for me) but it returns only one commodity number no matter what I enter. So it's not working. I suspect my error is at the end of the longest line...it had ticks and quotes that I deleted and those things get me every time.
Also, I researched online before asking the question, and the internet kept directing me to a wizard. I'm way too far in my DB to invoke that. Relationships are defined, tables, queries, and forms are made, etc.
Thanks in advance to the generous person who helps me!
Just for reference, here is the wonderful and working code I began with. cboCLASS no longer exists in new DB.
Code:
Option Compare Database
Option Explicit
Private Sub cboSize_AfterUpdate()
If Not IsNull(Me![cboSIZE]) Then
Me![txtCommodityNum] = DLookup("[BLANK_COMMODITY_NUM]", "tblBLANK_COMMODITY")
End If
End Sub
Private Sub cboClass_Change()
Call ChangeRowSource
End Sub
End Sub
Also, I researched online before asking the question, and the internet kept directing me to a wizard. I'm way too far in my DB to invoke that. Relationships are defined, tables, queries, and forms are made, etc.
Thanks in advance to the generous person who helps me!
Just for reference, here is the wonderful and working code I began with. cboCLASS no longer exists in new DB.
Code:
Option Compare Database
Option Explicit
Private Sub cboClass_AfterUpdate()
If Not IsNull(Me![CBOclass]) Then
Me![cboSIZE].RowSource = "SELECT [SIZE] FROM tblCOMMODITY WHERE [CLASS] = '" & Me![CBOclass] & "' ORDER BY CInt(IIf(IsNumeric(Right([SIZE],1)),[SIZE],Left([SIZE],Len([SIZE])-1)));"
End If
End Sub
Private Sub cboSize_AfterUpdate()
If Not IsNull(Me![CBOclass]) And Not IsNull(Me![cboSIZE]) Then
Me![txtCommodityNum] = DLookup("[COMMODITY_NUM]", "tblCOMMODITY", "[CLASS] = '" & Me![CBOclass] & _
"' And [SIZE] = '" & Me![cboSIZE] & "'")
End If
End Sub
Private Sub cboClass_Change()
Call ChangeRowSource
End Sub
Private Sub cboSize_Change()
Call ChangeRowSource
End Sub
Private Sub ChangeRowSource()
With Me
If Not IsNull(.CBOclass) And Not IsNull(.cboSIZE) Then
.txtCommodityNum = DLookup("[COMMODITY_NUM]", _
"tblCOMMODITY", _
"[CLASS] = '" & .CBOclass & "' And " & _
"[SIZE] = '" & .cboSIZE & "'")
End If
End With
End Sub
Comment