Protecting a Drop Down text Box - Block text entry.

  • Thread starter Thread starter Kahuna
  • Start date Start date
K

Kahuna

Hi Folks

I have a form on which one combo selection loads text into other fields on
the form. If the drop down is used the routines work very well, but if the
user types in a selection - even if it matches one of the combo entries I
get a Null error in one of the other fields.

Can I stop all text input to the combo and only allow the drop down to
populate it.

TIA
 
Kahuna said:
Hi Folks

I have a form on which one combo selection loads text into other
fields on the form. If the drop down is used the routines work very
well, but if the user types in a selection - even if it matches one
of the combo entries I get a Null error in one of the other fields.

Can I stop all text input to the combo and only allow the drop down to
populate it.

Better to figure out why keyboard entry in the combo isn't working the
same as mouse selection -- that way the combo box functions as users
expect it to. How have you set this up so that selecting from the combo
loads the other fields? Are you using code in one of the combo box's
events to do this? If so, what event and code?
 
Yes Dirk, I am using the On Change on the troublesome combo to do the work,
and the code is below - though its a bit long for this forum I suspect:

Any help appreciated Dirk
**************************************
Private Sub txt_Data_to_Mod_Change()
Dim dbCurr As Database, rst As Recordset
Dim rstLookup As Recordset
Dim flag As Boolean
Dim strSQL As String
Dim strSQL_Lookup As String
Dim txtRecHolder As String
Dim txtField_to_Mod As String
Dim txtReal_Field_Name As String
Dim txtField_Type
On Error GoTo Err_Err_txt_Data_to_Mod

Set dbCurr = CurrentDb

On Error Resume Next ' Skipping the Initial Data Error on Text
Input for testing purposes
txtField_to_Mod = Me![txt_Data_to_Mod]
On Error GoTo Err_Err_txt_Data_to_Mod

strSQL = "SELECT tbl_FabCon_Filed_Names_Types.TableName,
tbl_FabCon_Filed_Names_Types.FieldName,
tbl_FabCon_Filed_Names_Types.FieldType,
tbl_FabCon_Filed_Names_Types.FieldDescription,
tbl_FabCon_Filed_Names_Types.FieldRequired,
tbl_FabCon_Filed_Names_Types.FieldValidationText,
tbl_FabCon_Filed_Names_Types.FieldTypeDesc FROM
tbl_FabCon_Filed_Names_Types" ' WHERE [FieldDescription]= 'txtField_to_Mod'"

Set rst = dbCurr.OpenRecordset(strSQL)
rst.MoveFirst
Do While flag = False
If rst("FieldDescription") <> txtField_to_Mod Then
'MsgBox "this is the incorrect FieldDescription" &
rst("FieldDescription")
Else
'MsgBox "this is the correct FieldDescription" &
rst("FieldDescription")
Exit Do
End If
rst.MoveNext
Loop


Me![txt_box_Real_Field_Name] = rst!FieldName ' This is the real
field name to use in the data update
Me![txtField_Type] = rst!FieldType
Me![txtFieldTypeDesc] = rst!FieldTypeDesc

txtReal_Field_Name = rst!FieldName
txtField_Type = rst!FieldType
'MsgBox rst!FieldType

If Me!Frame11 = 1 Then 'If Only filtered records set then run this
SQL else run the other for entire database
strSQL_Lookup = "SELECT Distinct [" & txtReal_Field_Name & "]
FROM qryFabricCondition"
Else
strSQL_Lookup = "SELECT Distinct [" & txtReal_Field_Name & "]
FROM fabric_condition"
End If

Set rstLookup = dbCurr.OpenRecordset(strSQL_Lookup)
Me![txt_Where_equal_to].RowSource = strSQL_Lookup


Exit_Err_txt_Data_to_Mod:
Exit Sub

Err_Err_txt_Data_to_Mod:
MsgBox "a (" & Err.Source & "): Error " & Err.Number & ": " &
Err.description
Resume Exit_Err_txt_Data_to_Mod

End Sub
**********************************
 
Kahuna said:
Yes Dirk, I am using the On Change on the troublesome combo to do the
work, and the code is below - though its a bit long for this forum I
suspect:

That's not so long as many postings I've seen, so I wouldn't worry about
it. Without digging into the details of the code, though, I can tell
you that your main problem lies in your choice of the combo box's Change
event. This is not suitable for your purpose. You should use the combo
box's AfterUpdate event instead.

The reason you shouldn't use the Change event is that it fires
differently, and at different stages of the user's interaction with the
control, when the keyboard is used as opposed to when the mouse is used.
When you use the mouse to make a selection from a combo box, the Change
event fires once, at a point after the combo box's value has been
changed. When you use the keyboard to type in a value for the combo
box, though, the combo box fires once *for each keystroke that modifies
the displayed text*. Furthermore, under these conditions it fires as
the displayed text is being modified but *before* the value has been
updated. The control's Text property has been changed, but its Value
property has not.

Assuming that the code you posted works when the Change event is fired
by the user's mouse action, I imagine all you need to do is remove it
from the Change event and put it in the AfterUpdate event instead. That
always fires only once, after the control's Value property has been
updated.
 
Back
Top