|
 |
access thread: Formatting error with ComboBox.DefaultValue
Message #1 by "Dave Burdick" <burdickdave@h...> on Wed, 11 Dec 2002 22:37:13
|
|
Okay, I've got a form with a combo box on it. When the form is loaded, I
want to dynamically place a value from the combobox as the default value
for that combobox. The combobox is named 'CallerName', and I am using VBA
to write the query. The CallerName field is text formatted, with a length
of 50, which shouldn't be a problem.
When the form loads, I setup a recordset object to search for a field that
equals "Yes". This query will always return 1 item. I used a msgbox to
show the value for debugging purposes, and it returned the correct value.
The next step is I loop through the values in the combobox to see if the
queried value is in the combobox, which it will be. If a value in the
combobox equals the queried value, then I set that combobox value as the
default value. Here is the code:
------------------------
Private Sub Form_Load()
Dim rsFiles As Recordset, strSQL As String, currdb As Database, strDef
As String, i As Integer
Set currdb = CurrentDb
strSQL = "SELECT User.User, User.primary_tester FROM User WHERE
User.primary_tester = Yes"
Set rsFiles = currdb.OpenRecordset(strSQL)
For i = 0 To CallerName.ListCount - 1
If CallerName.Column(0, i) = rsFiles("User") Then
CallerName.DefaultValue = CallerName.ItemData(i)
Exit For
End If
Next i
rsFiles.Close
Set rsFiles = Nothing
currdb.Close
Set currdb = Nothing
End Sub
-------------------
Hope someone can help out. Thanks.
Message #2 by "Dave Burdick" <burdickdave@h...> on Wed, 11 Dec 2002 22:40:36
|
|
Sorry, I forgot to add my results. Like I said, the message box I used
for debugging showed the correct value, but when the form opens, the
default value in the combobox displays the "#Name" error message. Anyone
possibly know why this is happening?
> Okay, I've got a form with a combo box on it. When the form is loaded,
I
w> ant to dynamically place a value from the combobox as the default value
f> or that combobox. The combobox is named 'CallerName', and I am using
VBA
t> o write the query. The CallerName field is text formatted, with a
length
o> f 50, which shouldn't be a problem.
> When the form loads, I setup a recordset object to search for a field
that
e> quals "Yes". This query will always return 1 item. I used a msgbox to
s> how the value for debugging purposes, and it returned the correct
value.
T> he next step is I loop through the values in the combobox to see if the
q> ueried value is in the combobox, which it will be. If a value in the
c> ombobox equals the queried value, then I set that combobox value as the
d> efault value. Here is the code:
-> -----------------------
P> rivate Sub Form_Load()
> Dim rsFiles As Recordset, strSQL As String, currdb As Database,
strDef
A> s String, i As Integer
> Set currdb = CurrentDb
> strSQL = "SELECT User.User, User.primary_tester FROM User WHERE
U> ser.primary_tester = Yes"
> Set rsFiles = currdb.OpenRecordset(strSQL)
>
> For i = 0 To CallerName.ListCount - 1
> If CallerName.Column(0, i) = rsFiles("User") Then
> CallerName.DefaultValue = CallerName.ItemData(i)
> Exit For
> End If
> Next i
> rsFiles.Close
> Set rsFiles = Nothing
> currdb.Close
> Set currdb = Nothing
> End Sub
-> ------------------
H> ope someone can help out. Thanks.
|
|
 |