ListBox default value

J

John Ingato

I have a combobox on a customer form called LocationChooser which list the
properties this customer own.
When the form opens, the CB is empty (no default value) forcing the user to
choose a location

I would like to have it so if there is only one location in the list, it
would be automatically selected. I have tried the following code, which is
in the Form_Load of the customer form:
--------------------------------------------------------
Me.LocationChooser.RowSource = "SELECT JobLocations.LocationID,
JobLocations.LocationNickName" & _
" FROM JobLocations WHERE (((JobLocations.CustomerID)= " &
m_CustomerID & "));"

If Me.LocationChooser.ListCount = 1 Then

Me.LocationChooser.Selected(0) = True

End If
 
J

John Ingato

Sorry. m_CustomerID is a private var in the form which gets set to Openargs

Private m_CustomerID As Long

Private Sub Form_Load()
' This form is always passed a customerID thru openArgs
' If openArgs is empty then there isn't a customerID to attach this event
to.
' This form will never open without that passed variable

If IsNull(OpenArgs) Then
MsgBox "This form cannot be open from this location." & vbCrLf & _
"Please choose a customer from the Customer List first!"
DoCmd.Close acForm, Me.Name
Exit Sub
End If


m_CustomerID = OpenArgs
m_now = Now()

Me.RecordSource = ""
Me.DataEntry = True
Me.OpenedDate = Format(Now(), "mmmm dd, yyyy")

Me.FullName = DLookup("FullName", "CustomersExtended",
"((CustomersExtended.CustomerID)= " & m_CustomerID & ")")

Me.LocationChooser.RowSource = "SELECT JobLocations.LocationID,
JobLocations.LocationNickName" & _
" FROM JobLocations WHERE (((JobLocations.CustomerID)= " &
m_CustomerID & "));"

If LocationChooser.ListCount = 1 Then
Me.LocationChooser.Selected(0) = True
End If

End Sub
 
K

Klatuu

Have you run your code in debug mode? I don't see a problem that jumps out
at me.
Any particular reason you are using an unbound form?
 
J

John Ingato

Well. I probably dont need to. I was trying to learn to assemble append
queries on the fly. I guess I felt it gave me more control, allowing me to
easily just close the form without updating if I want to. Also, I was
learning for the future; attempting to work with a non-access database.

Bottom line: I am not that good with Access. Still have a large learning
curve to climb. I am better with handling things programatically. I am more
comfortable creating recordsets programatically the writing queries.

But that was all before I found this newsgroup!

Should I just take the plunge? lol (in your opinion)
 
J

John Ingato

Also. My goals are to rewite the code in Visual Basic not VBA. I would
like to have a stand alone package with a clean interface. Not forms
opening up in Access. Is this possible in Access? Can I minimze Access
completely while my forms are open? Maybe thru hWnd?
 
K

Klatuu

To answer both of your posts.
I would suggest to always use bound forms in Access.
If you want to use VB, why are you bothering to use Access at all?

I don't know what you mean by clean interface. You can do some pretty clean
UI with Access. You can even hide the Access window with a little advanced
coding.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top