kealaz said:
Dirk,
Thank you so much, you've been a huge help. I understand that this is
unusual, and you are correct, I'm sure I have problems with my initial
design. I'm trying to convert a database that was written in dbase IV
about
20 years ago by someone else, to Access 2003. I wouldn't know where to
start
to try and re-design the tables and not lose info.
The application of this little bit that I'm asking about is for a
purchasing
program. I have a part and each part can have up to, but never any more
than
3 manufacturers. Since there would not be more than 3 mfgs, I think I can
get it to work, if I can figure out a way to get the fields in that second
combo box to populate with columns 2, 3, and 4 from the first combo box.
I have entered the code you gave me in the After Update code area. Should
it work? Am I supposed to make any changes to the second combo box (the
one
receiving the values)? Right now, it is...
unbound
Control Source: [blank]
Row Source Type: Value List
Row Source: [blank]
I can't say whether the ControlSource of the second combo box should be
blank or not -- that depends on whether you intend for the selected value to
be stored directly in the form's underlying table or not. However, the rest
of that looks correct.
There was a small bug in the code I gave in my previous post -- I left out
an End If statement. Did you discover that? Other than that, it should
work -- in principle, of course, and after the names have been corrected.
Be aware that columns 2, 3, and 4 of a combo box will be known in code by
..Column(1), .Column(2), and .Column(3), because the .Column collection is
0-based.
Here's some revised code, based on the information you've given me in this
post:
'----- start of revisd code -----
Private Sub cboFirst_AfterUpdate()
Const Q As String = """"
Dim I As Long
Dim strRowSource As String
Dim strValue As String
With Me.cboFirst
If IsNull(.Value) Then
Me.cboSecond.RowSource = ""
Else
For I = 1 To 3
strValue = .Column(I) & vbNullString
If Len(strValue) > 0 Then
strRowSource = strRowSource & ";" & Q & strValue & Q
End If
Next I
Me.cboSecond.RowSource = Mid$(strRowSource, 2)
End If
End With
End Sub
'----- end of revised code -----
Be sure to correct the names "cboFirst" and "cboSecond" that I've used in
the above code. And note that this is for the AfterUpdate event of the
combo box, not the form itself.
If this doesn't work, it's possible that the cboSecond should be
representing numeric values, not strings. In that case, set the rowsource
without the quotes:
strRowSource = strRowSource & ";" & strValue
Also, if this doesn't seem to be working, give me the real names of the
controls and the data types of the fields involved, and maybe we can get
more specific.