Re: Pre-position a combo box

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Sorry for the mixup Bill. Just in case, the 'Text1' is actually a text box
control on the form along with a combo box and a command button. I set the
value for the text box to a name in the Customers table. I then could call
it's value property by using 'Me.Text1' to get the name and pass it to my SQL
string. I'm glad it worked.

Regards,

Paul



"Bill" wrote:

Well Paul, in spite of my intuitive thoughts to the
contrary, I adapted the exact code you posted
(adjusted, of course, for my stuff) and it worked
perfectly.
Thanks,
Bill



"Paul" <Paul@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E6537C26-B2C7-4F63-9DAF-604E332BCE52@xxxxxxxxxxxxxxxx
Sorry Bill, but you have to remove the additional space between the first
single quote and the first double quote and the second single quote and
the
second double quote in the SQL statement. I put them in my response to
make
it easier to identify them. Thanks.



"Paul" wrote:

Hello Bill,

You'll have to query the table by the new record's name. Try this in the
Northwind sample db:


Private Sub Command0_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQl As String

strSQl = "SELECT CustomerID, CompanyName " & _
"FROM Customers " & _
"WHERE CompanyName = ' " & Me.Text1 & " ';"

Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQl, dbOpenSnapshot)

With rs
rs.MoveFirst

' Prints to immediate window to debug.
Debug.Print .Fields(0) & vbTab & _
.Fields(1) & vbTab

Me.Combo3.DefaultValue = " ' " & .Fields(0) & " ' "

.MoveNext

End With

Set db = Nothing
Set rs = Nothing

End Sub


Hope this helps.

Regards,

Paul




"Bill" wrote:

Default Value won't help me if I don't know the
index of the newly added record.....or am I
missing something here?
Bill


"Paul" <Paul@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:CD306C9D-B202-40A8-87DC-67F96268CC21@xxxxxxxxxxxxxxxx
Hello Bill,

Take a look at the control's default value property in the help file.
That
should help.

Regards,

Paul


"Bill" wrote:

How does one pre-position a select in
a combo box?

I've just added a new record to the Rowsource
and have Required the combo and want to have
the newly added record pre-selected following
the Requery.

I would necessarily have to find the item based
on its display name, as I don't yet have its newly
assigned autonumber.

Thanks,
Bill









.



Relevant Pages

  • Re: Pre-position a combo box
    ... "Bill" wrote: ... it's index position. ... Dim rs As DAO.Recordset ... Take a look at the control's default value property in the help file. ...
    (microsoft.public.access.formscoding)
  • Re: Pre-position a combo box
    ... it's index position. ... Dim rs As DAO.Recordset ... "Bill" wrote: ... Take a look at the control's default value property in the help file. ...
    (microsoft.public.access.formscoding)
  • Re: Pre-position a combo box
    ... Sorry Bill, but you have to remove the additional space between the first ... single quote and the first double quote and the second single quote and the ... Dim rs As DAO.Recordset ...
    (microsoft.public.access.formscoding)
  • Re: Pre-position a combo box
    ... Not in my 2003 Northwind. ... single quote and the first double quote and the second single quote and ... "Bill" wrote: ...
    (microsoft.public.access.formscoding)
  • Re: Pre-position a combo box
    ... Private Sub Command0_Click ... Dim rs As DAO.Recordset ... "Bill" wrote: ... Take a look at the control's default value property in the help file. ...
    (microsoft.public.access.formscoding)