Unable to populate text box from combo box 
Author Message
 Unable to populate text box from combo box

I have a combo box with a list of function names populated from a table.
When the user selects the function in the combo box, I want it to populate a
textbox with the actual function code, which also resides in the same table,
and is in fact part of the same record.

It seems this should be easy, but I've looked at it for a couple of days
now.  Whenever I run my code (in the Click event for the combo box), I
receive an error :

2115 --(The macro or function set to the BeforeUpdate or ValidationRule
property for this field is preventing Microsoft Access from saving the data

remove the action that forces a save (for example, GoToControl).
* If the macro includes a SetValue action, set the macro to the AfterUpdate
property of the control instead.
* If this is a function, redefine the function in the Module window.)

I've looked at the BeforeUpdate event and ValidationRule for this combo box,
and there are no rules or event code to prevent this.  I also looked at the
events and rules for the encompassing form, and there were no rules or code.

My click event code for the combo box is as follows:

Private Sub Combo0_Click()
  Dim SQLstmt As String
  Dim WrkJet As Workspace
  Dim Db As Database
  Dim Rs As Recordset
  Dim FunctionCode As String

  Set WrkJet = CreateWorkspace("", "Admin", "", dbUseJet)
  Set Db = WrkJet.OpenDatabase("q:\juan\functions.mdb")
  SQLstmt = "select FunctionCode from mdmLibrary where FunctionID=" &
Combo0.BoundColumn
  Set Rs = Db.OpenRecordset(SQLstmt, dbOpenForwardOnly)
  If Not (Rs.BOF And Rs.EOF) Then
    FunctionCode = Rs.Fields("FunctionCode")
  End If
  Rs.Close
  Db.Close
  WrkJet.Close
  Text21.SetFocus
  Me![Text21].Text = FunctionCode
End Sub



Tue, 26 Mar 2002 03:00:00 GMT  
 Unable to populate text box from combo box
Juan,
A couple of suggestions in-line.

HTH,
Doug


Quote:
> SNIP
> My click event code for the combo box is as follows:

> Private Sub Combo0_Click()

It would be more appropriate to put this code in the AfterUpdate event of
the combo-box. Use AfterUpdate when you want to do something after the item
has changed.

Quote:
>   Dim SQLstmt As String
>   Dim WrkJet As Workspace
>   Dim Db As Database
>   Dim Rs As Recordset
>   Dim FunctionCode As String

>   Set WrkJet = CreateWorkspace("", "Admin", "", dbUseJet)
>   Set Db = WrkJet.OpenDatabase("q:\juan\functions.mdb")
>   SQLstmt = "select FunctionCode from mdmLibrary where FunctionID=" &
> Combo0.BoundColumn

This probably should say:
SQLstmt = "select FunctionCode from mdmLibrary where FunctionID=" &
Combo0.Value

Otherwise you will always retrieve the same function from the query,
BoundColumn specifies the column to use when binding data, not the data
itself.

Quote:
>   Set Rs = Db.OpenRecordset(SQLstmt, dbOpenForwardOnly)
>   If Not (Rs.BOF And Rs.EOF) Then
>     FunctionCode = Rs.Fields("FunctionCode")
>   End If
>   Rs.Close
>   Db.Close
>   WrkJet.Close
>   Text21.SetFocus
>   Me![Text21].Text = FunctionCode

You could set the value this way, but it would be easier (and less error
prone) to simply state:
Me![Text21].Value = FunctionCode
Quote:
> End Sub



Tue, 26 Mar 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. populate text box from combo box (same form)

2. Populating a combo box from another combo box

3. Populate a combo box from another combo box selection

4. Limiting Access to Text Boxes, List Boxes and Combo Boxes

5. populating a combo box with an external text file

6. Populating a combo box from a text file

7. Databound combo boxes don't populate text field after Find

8. Beginner: Populating text box by selecting from list box

9. Putting a value from a combo box into a text box on a form

10. Filling combo box text box area from data

11. Created Form in Word - Irregular movement of combo boxes, text boxes on scrolling

12. Adding to a combo box or text box through the keyboard

 

 
Powered by phpBB® Forum Software