Re: Pre-position a combo box

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



Yep, sometimes there are things that seem so trivial and easy to the user
where it takes them a second or two to complete may actually take the
programmer a hundred (or more) lines of code just to accomplish the task and
ease usability concerns. I'm finding that having a library of snippets of
code of various tasks can make things a whole lot easier. Thanks.


"Bill" wrote:

Hi Paul,
Would you believe that I was about to post that the
only way I could see to utilize the DefaultValue
property would be to first open a DAO Recordset
and locate the newly added record to determine
it's index position. BUT, that I was having a hard
time believing that it required all that effort for what
would seem like a small matter......OH WELL!
Thanks,
Bill

"Paul" <Paul@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5A47962F-4E12-4661-8DF9-79B7E4D6B0D9@xxxxxxxxxxxxxxxx
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
    ... 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 for the mixup Bill. ... single quote and the first double quote and the second single quote and ... 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
    ... 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)
  • Re: Create my own db connection wizard
    ... William (Bill) Vaughn ... Dim colService As New DataColumn ... providers and the servers/instances of those database providers. ... Factory Class I cannot find a reference to that anywhere. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Dim Name
    ... >From the Help file: ... arguments in a Visual Basic module: ... can't declare two variables named age within the same procedure. ... > I'm trying to figure it out how to accept using DIM when using "&" ...
    (microsoft.public.access.formscoding)