Is it Possible to Populate a Combobox From an Autopopulated Textbox?

  • Thread starter DataDiva via AccessMonster.com
  • Start date
D

DataDiva via AccessMonster.com

Hi All,

Can't quite seem to get my arms around this one! I have two forms in my
database. The first is to track the inspection of PCB boards as they go
through the manufacturing process [frmBoardInspection]. The second form is to
record any defects found on the boards during inspection [frmBoardDefects].
[frmBoardInspection] has twelve fields where the user will enter data about
the inspection of a particular board. On that form there is a combo box named
[Department] that has a lookup to a table called [LDepartments]. The last
field on the form is a combo box called [Defects_Present]. This cbo also has
a lookup to a table. If the user chooses "no" defects then the record can be
saved and they can start a new record. If the user selects "Yes" to defects,
a command button to open [frmBoardDefects] is enabled. There are seven fields
in [frmBoardDefects]. I have two cascading combo boxes named [cboDepartment]
and [Error_Code]. Currently I have this code in the after update event of
[cboDepartment]:

Private Sub DefectDepartment_AfterUpdate()
On Error Resume Next
Select Case DefectDepartment.Value
Case "AOI"
ErrorCode.RowSource = "LPCB"
Case "Bench"
ErrorCode.RowSource = "LPCB"
Case "Final"
ErrorCode.RowSource = "LPCB"
Case "In Process"
ErrorCode.RowSource = "LPCB"
Case "Box Build"
ErrorCode.RowSource = "LBoxBuild"
Case "Cable"
ErrorCode.RowSource = "LCable"
Case "FCT"
ErrorCode.RowSource = "LTest"
Case "ICT"
ErrorCode.RowSource = "LTest"
End Select

This seems to be working fine. What I would like to do is have the value in
the [Department] field carry over from [frmBoardInspection] and populate the
[Error_Code] field in [frmBoardDefects]. I'm not quite sure how to do this
because frmBoardDefects will not necessarily always be opened. I have tried
putting [Forms]![frmBoardInspection]![Department] into the default value of
the [Department] field in [frmBoardDefects]. This populates the [Department]
field but, does not populate the [Error_Code]. I'm not really sure how to
make this work right and I have a feeling my way of thinking is off. Any
insight would be very helpful!

Thanks

Courtney
 
N

NetworkTrade

the [Department] field carry over from [frmBoardInspection] and populate the
[Error_Code] field in [frmBoardDefects].

I have tried putting [Forms]![frmBoardInspection]![Department] into the
default value of the [Department] field in [frmBoardDefects]. This populates
the [Department] field but, does not populate the [Error_Code].

** At some appropriate event of frmBoardDefects put:
me.Error_Code= [Forms]![frmBoardInspection].[Department]
 
D

DataDiva via AccessMonster.com

Hi

Thank you for your suggestion! I tried putting the code into the Got Focus
event of frmBoardDefects. This populated the ErrorCode field with the
Department name from frmBoardInspection. I changed the code to

Private Sub DefectDepartment_GotFocus()
Me.Department = [Forms]![frmBoardInspection].[Department]
End Sub

This populates the Department field in frmBoardDefects with the same
Department value from frmBoardInspection. That's what I wanted. My problem is
that the user will have to go back and re-pick the Department in
frmBoardDefects to have the Error_Code field populate with all of the
different department error codes. I think I may have poorly explained what my
issue really was in my last post. Any other suggestions would be appreciated!

Thanks

Courtney
 
N

NetworkTrade

I do not understand what is meant by:

have the Error_Code field populate with all of the different department
error codes


1 field is to populate with multiple codes???
 
D

DataDiva via AccessMonster.com

Sorry, I will try to explain again!
In frmBoardDefects the Department field is a cascading combo to the
Error_Code field. I used this code in the AfterUpdate event of the Department
field.

Private Sub DefectDepartment_AfterUpdate()
On Error Resume Next
Select Case DefectDepartment.Value
Case "AOI"
ErrorCode.RowSource = "LPCB"
Case "Bench"
ErrorCode.RowSource = "LPCB"
Case "Final"
ErrorCode.RowSource = "LPCB"
Case "In Process"
ErrorCode.RowSource = "LPCB"
Case "Box Build"
ErrorCode.RowSource = "LBoxBuild"
Case "Cable"
ErrorCode.RowSource = "LCable"
Case "FCT"
ErrorCode.RowSource = "LTest"
Case "ICT"
ErrorCode.RowSource = "LTest"
End Select

Once a user picks a department, the corresponding error codes populate the
Error_Code combo box. What I wanted to do is auto populate the Department
field in frmBoardDefects with the department value in frmBoardInspection
since they will be the same. Once I auto populate the Department field, the
problem I'm having is that nothing populates the Error_Code field in
frmBoardDefects unless I go back and re-select the Department choice. I tried
changing the Department field in frmBoardDefects to a textbox but, I still
have to cut and paste the value back in to get anything to show up in the
Error_Code field. I don't know what I am missing. I hope I did a better job
explaining this time!

Thanks for the help!

Courtney
 
N

NetworkTrade

The essence of your question concerns that the ErrorCode value is populated
via VBA triggered by an event - the AfterUpdate of the DefectDepartment
combobox.

When you auto populate this defectdepartment combobox from
frmBoardInspection - then there is no AfterUpdate event. An AfterUpdate
event is when the user makes a selection not when it is updated via VBA. So
there is no trigger for your ErrorCode value.

You need to move the code to an event that will serve as a trigger to run
the code.
 
D

DataDiva via AccessMonster.com

Hello

I moved the code into the On Open event of frmBoardDefects and it seems to be
working quite well! Many thanks for your patience and advice!

Courtney
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top