Listbox and combo problem

J

Jac Tremblay

Hi,
I created a simple form with no record source. I just want to set some
parameters through it.
I placed on it a listbox (lstCommande) and a combobox (cboLogoRepas) with no
record source to start with. Their record source is set in the Form_Load
Event.
When the form is displayed the two lists do not work. The list and the combo
do not allow any selection (the contents is OK in both).
What could be the problem?
Here's the Form_Load code:
Private Sub Form_Load()
Dim strSql As String
MsgBox "lngIdRés = " & lngIdRés
' Fill the list.
strSql = "SELECT tblCommande.DateCommande " & _
"FROM tblCommande " & _
"WHERE (((tblCommande.IdRéservation) = " & lngIdRés & _
")) ORDER BY tblCommande.DateCommande; "
Me.lstCommande.RowSource = strSql
Me.lstCommande.SetFocus
Me.lstCommande.Enabled = True
Me.lstCommande.Selected(0) = True
' Fill the combo.
strSql = "SELECT tblLogo.IdLogo, tblLogo.NomLogo " & _
"FROM tblLogo ORDER BY tblLogo.IdLogo; "
Me.cboLogoRepas.RowSource = strSql
End Sub
I am completely lost.
Thanks
 
J

Jeanette Cunningham

When the form has no record source, the code can't find what value to use
for lngIdRés.
Access can't get the data for the row source for the listbox.

If you are supplying a value for lngIdRés somewhere else, then put a
debug.print statement after the sql like this.

strSql = "SELECT tblCommande.DateCommande " & _
"FROM tblCommande " & _
"WHERE (((tblCommande.IdRéservation) = " & lngIdRés & _
")) ORDER BY tblCommande.DateCommande; "
Debug.Pring strsql

Open the form, then open the immediate window to see what access prints for
the sql.
Copy and paste the sql into the sql view of a new query.
Switch the query to datasheet view to see what is wrong with the sql.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

Jac Tremblay

Hi Jeannette,
This form is opened from a command button on a reservation form and the
lngIdRés is a global variable set in the first form. That is why I put this
line at the beginning to make sure it is set alright:
MsgBox "lngIdRés = " & lngIdRés
I tried what you suggested and everything is fine. Both strSql strings are
OK and provide the right data.
That is the reason I cannot figure out what is wrong with the list and the
combo. They do not allow selection.
I tried to set the form's record source. Nothing changed.
I tried to set the listbox record source. Same result.
I deleted the list and recreated it to no avail.
What else could I try?
Thanks for your comment. I will keep on looking for a solution.
Must be the full moon...
 
J

Jeanette Cunningham

Here are some other things to try.
Make sure that the form has allow edits set to Yes.

Make sure the listbox and combo have the correct number of columns for their
queries.

Assume the form is corrupted and make a new form and copy the listbox and
combo to the new form.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

Jac Tremblay

Hi Jeanette,

I deleted the form. I created a new one with brand new controls on it. It
works fine. Both the list and the combo work fine and I can transfer the
combo selection (the IdLogo) in a text field (whose Control Source is
"=[cboLogoRepas]" without the quotes). Thanks for your comments. They're
appreciated.

But I wander, for a combo or a listbox control, what is the Control Source
for?
I understand that the Row Source is the list of rows to be displayed in the
control.
I understand as well that a text field that has its Control Source set to a
listbox or combo will display the selected value in that control.

Another point:
Now that I have the IdLogo, can I display the corresponding image that is
stored in the tblLogo with this line:
=DLookUp([tblLogo]![ImageLogo];[tblLogo];[txtIdLogo]=[tblLogo]![IdLogo])
I tried that and the image does not show at all.
If you do not know, no problem. I still appreciate your comments.
Have a good day.
 
J

Jeanette Cunningham

1. what is the Control Source for?

The control source is used when you are doing data entry.
For instance you might need user to choose the state or province,
The combo would have the state field from the table as its control source.
It would have a query based on a list of the state names as its row source.
When the user chooses a state from the list, that State is saved in that row
of that table.


2. Images are best displayed in an unbound image control - look in the
toolbox controls near combo, listbox etc.
You can use code to set the image to show in the image control.
I haven't tried this, but something like:


Private Sub ShowImage
Dim strPicture As String
strPicture = "C:\Users\Pic2948.bmp"
Me.ImageControlName.Picture = strPicture
EndSub

Note: strPicture is the path and name of the picture.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Jac Tremblay said:
Hi Jeanette,

I deleted the form. I created a new one with brand new controls on it. It
works fine. Both the list and the combo work fine and I can transfer the
combo selection (the IdLogo) in a text field (whose Control Source is
"=[cboLogoRepas]" without the quotes). Thanks for your comments. They're
appreciated.

But I wander, for a combo or a listbox control, what is the Control Source
for?
I understand that the Row Source is the list of rows to be displayed in
the
control.
I understand as well that a text field that has its Control Source set to
a
listbox or combo will display the selected value in that control.

Another point:
Now that I have the IdLogo, can I display the corresponding image that is
stored in the tblLogo with this line:
=DLookUp([tblLogo]![ImageLogo];[tblLogo];[txtIdLogo]=[tblLogo]![IdLogo])
I tried that and the image does not show at all.
If you do not know, no problem. I still appreciate your comments.
Have a good day.
--
Jac Tremblay


Jeanette Cunningham said:
Here are some other things to try.
Make sure that the form has allow edits set to Yes.

Make sure the listbox and combo have the correct number of columns for
their
queries.

Assume the form is corrupted and make a new form and copy the listbox and
combo to the new form.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia





.
 
J

Jac Tremblay

Hi again Jeanette,

Thank you for these simple and accurate information.

1- Control Source: great explanation.

2- Image, also very simple. That's what I eventually ended up doing since
the way I was trying to do will not work.

Actually, my images are stored in the database (i've got only 6 little logos
and there will never be any more). I was trying to lookup the imageLogo from
the IdLogo. The code I wrote for that is similar to the one used to lookup
the NameLogo:
Me.imgTest.Picture = DLookup("[tblLogo]![ImageLogo]", "[tblLogo]", _
"[tblLogo]![IdLogo] = " & CInt(Me.txtIdLogo))
I get an error and I can't figure out what to do.

But that is not your problem. I will stick to the other way of doing since
it works well.

Thank you again, Jeanette. I really appreciate your comments.
Have a nice day.
--
Jac Tremblay


Jeanette Cunningham said:
1. what is the Control Source for?

The control source is used when you are doing data entry.
For instance you might need user to choose the state or province,
The combo would have the state field from the table as its control source.
It would have a query based on a list of the state names as its row source.
When the user chooses a state from the list, that State is saved in that row
of that table.


2. Images are best displayed in an unbound image control - look in the
toolbox controls near combo, listbox etc.
You can use code to set the image to show in the image control.
I haven't tried this, but something like:


Private Sub ShowImage
Dim strPicture As String
strPicture = "C:\Users\Pic2948.bmp"
Me.ImageControlName.Picture = strPicture
EndSub

Note: strPicture is the path and name of the picture.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Jac Tremblay said:
Hi Jeanette,

I deleted the form. I created a new one with brand new controls on it. It
works fine. Both the list and the combo work fine and I can transfer the
combo selection (the IdLogo) in a text field (whose Control Source is
"=[cboLogoRepas]" without the quotes). Thanks for your comments. They're
appreciated.

But I wander, for a combo or a listbox control, what is the Control Source
for?
I understand that the Row Source is the list of rows to be displayed in
the
control.
I understand as well that a text field that has its Control Source set to
a
listbox or combo will display the selected value in that control.

Another point:
Now that I have the IdLogo, can I display the corresponding image that is
stored in the tblLogo with this line:
=DLookUp([tblLogo]![ImageLogo];[tblLogo];[txtIdLogo]=[tblLogo]![IdLogo])
I tried that and the image does not show at all.
If you do not know, no problem. I still appreciate your comments.
Have a good day.
--
Jac Tremblay


Jeanette Cunningham said:
Here are some other things to try.
Make sure that the form has allow edits set to Yes.

Make sure the listbox and combo have the correct number of columns for
their
queries.

Assume the form is corrupted and make a new form and copy the listbox and
combo to the new form.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Hi Jeannette,
This form is opened from a command button on a reservation form and the
lngIdRés is a global variable set in the first form. That is why I put
this
line at the beginning to make sure it is set alright:
MsgBox "lngIdRés = " & lngIdRés
I tried what you suggested and everything is fine. Both strSql strings
are
OK and provide the right data.
That is the reason I cannot figure out what is wrong with the list and
the
combo. They do not allow selection.
I tried to set the form's record source. Nothing changed.
I tried to set the listbox record source. Same result.
I deleted the list and recreated it to no avail.
What else could I try?
Thanks for your comment. I will keep on looking for a solution.
Must be the full moon...
--
Jac Tremblay


:

When the form has no record source, the code can't find what value to
use
for lngIdRés.
Access can't get the data for the row source for the listbox.

If you are supplying a value for lngIdRés somewhere else, then put a
debug.print statement after the sql like this.

strSql = "SELECT tblCommande.DateCommande " & _
"FROM tblCommande " & _
"WHERE (((tblCommande.IdRéservation) = " & lngIdRés & _
")) ORDER BY tblCommande.DateCommande; "
Debug.Pring strsql

Open the form, then open the immediate window to see what access
prints
for
the sql.
Copy and paste the sql into the sql view of a new query.
Switch the query to datasheet view to see what is wrong with the sql.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Hi,
I created a simple form with no record source. I just want to set
some
parameters through it.
I placed on it a listbox (lstCommande) and a combobox (cboLogoRepas)
with
no
record source to start with. Their record source is set in the
Form_Load
Event.
When the form is displayed the two lists do not work. The list and
the
combo
do not allow any selection (the contents is OK in both).
What could be the problem?
Here's the Form_Load code:
Private Sub Form_Load()
Dim strSql As String
MsgBox "lngIdRés = " & lngIdRés
' Fill the list.
strSql = "SELECT tblCommande.DateCommande " & _
"FROM tblCommande " & _
"WHERE (((tblCommande.IdRéservation) = " & lngIdRés & _
")) ORDER BY tblCommande.DateCommande; "
Me.lstCommande.RowSource = strSql
Me.lstCommande.SetFocus
Me.lstCommande.Enabled = True
Me.lstCommande.Selected(0) = True
' Fill the combo.
strSql = "SELECT tblLogo.IdLogo, tblLogo.NomLogo " & _
"FROM tblLogo ORDER BY tblLogo.IdLogo; "
Me.cboLogoRepas.RowSource = strSql
End Sub
I am completely lost.
Thanks
--
Jac Tremblay


.



.


.
 
J

Jeanette Cunningham

The DLookup will only work if
"[tblLogo]![ImageLogo]"
is the full path with name of the image file.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

Jac Tremblay said:
Hi again Jeanette,

Thank you for these simple and accurate information.

1- Control Source: great explanation.

2- Image, also very simple. That's what I eventually ended up doing since
the way I was trying to do will not work.

Actually, my images are stored in the database (i've got only 6 little
logos
and there will never be any more). I was trying to lookup the imageLogo
from
the IdLogo. The code I wrote for that is similar to the one used to lookup
the NameLogo:
Me.imgTest.Picture = DLookup("[tblLogo]![ImageLogo]", "[tblLogo]", _
"[tblLogo]![IdLogo] = " & CInt(Me.txtIdLogo))
I get an error and I can't figure out what to do.

But that is not your problem. I will stick to the other way of doing since
it works well.

Thank you again, Jeanette. I really appreciate your comments.
Have a nice day.
--
Jac Tremblay


Jeanette Cunningham said:
1. what is the Control Source for?

The control source is used when you are doing data entry.
For instance you might need user to choose the state or province,
The combo would have the state field from the table as its control
source.
It would have a query based on a list of the state names as its row
source.
When the user chooses a state from the list, that State is saved in that
row
of that table.


2. Images are best displayed in an unbound image control - look in the
toolbox controls near combo, listbox etc.
You can use code to set the image to show in the image control.
I haven't tried this, but something like:


Private Sub ShowImage
Dim strPicture As String
strPicture = "C:\Users\Pic2948.bmp"
Me.ImageControlName.Picture = strPicture
EndSub

Note: strPicture is the path and name of the picture.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Jac Tremblay said:
Hi Jeanette,

I deleted the form. I created a new one with brand new controls on it.
It
works fine. Both the list and the combo work fine and I can transfer
the
combo selection (the IdLogo) in a text field (whose Control Source is
"=[cboLogoRepas]" without the quotes). Thanks for your comments.
They're
appreciated.

But I wander, for a combo or a listbox control, what is the Control
Source
for?
I understand that the Row Source is the list of rows to be displayed in
the
control.
I understand as well that a text field that has its Control Source set
to
a
listbox or combo will display the selected value in that control.

Another point:
Now that I have the IdLogo, can I display the corresponding image that
is
stored in the tblLogo with this line:
=DLookUp([tblLogo]![ImageLogo];[tblLogo];[txtIdLogo]=[tblLogo]![IdLogo])
I tried that and the image does not show at all.
If you do not know, no problem. I still appreciate your comments.
Have a good day.
--
Jac Tremblay


:

Here are some other things to try.
Make sure that the form has allow edits set to Yes.

Make sure the listbox and combo have the correct number of columns for
their
queries.

Assume the form is corrupted and make a new form and copy the listbox
and
combo to the new form.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Hi Jeannette,
This form is opened from a command button on a reservation form and
the
lngIdRés is a global variable set in the first form. That is why I
put
this
line at the beginning to make sure it is set alright:
MsgBox "lngIdRés = " & lngIdRés
I tried what you suggested and everything is fine. Both strSql
strings
are
OK and provide the right data.
That is the reason I cannot figure out what is wrong with the list
and
the
combo. They do not allow selection.
I tried to set the form's record source. Nothing changed.
I tried to set the listbox record source. Same result.
I deleted the list and recreated it to no avail.
What else could I try?
Thanks for your comment. I will keep on looking for a solution.
Must be the full moon...
--
Jac Tremblay


:

When the form has no record source, the code can't find what value
to
use
for lngIdRés.
Access can't get the data for the row source for the listbox.

If you are supplying a value for lngIdRés somewhere else, then put
a
debug.print statement after the sql like this.

strSql = "SELECT tblCommande.DateCommande " & _
"FROM tblCommande " & _
"WHERE (((tblCommande.IdRéservation) = " & lngIdRés & _
")) ORDER BY tblCommande.DateCommande; "
Debug.Pring strsql

Open the form, then open the immediate window to see what access
prints
for
the sql.
Copy and paste the sql into the sql view of a new query.
Switch the query to datasheet view to see what is wrong with the
sql.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Hi,
I created a simple form with no record source. I just want to set
some
parameters through it.
I placed on it a listbox (lstCommande) and a combobox
(cboLogoRepas)
with
no
record source to start with. Their record source is set in the
Form_Load
Event.
When the form is displayed the two lists do not work. The list
and
the
combo
do not allow any selection (the contents is OK in both).
What could be the problem?
Here's the Form_Load code:
Private Sub Form_Load()
Dim strSql As String
MsgBox "lngIdRés = " & lngIdRés
' Fill the list.
strSql = "SELECT tblCommande.DateCommande " & _
"FROM tblCommande " & _
"WHERE (((tblCommande.IdRéservation) = " & lngIdRés & _
")) ORDER BY tblCommande.DateCommande; "
Me.lstCommande.RowSource = strSql
Me.lstCommande.SetFocus
Me.lstCommande.Enabled = True
Me.lstCommande.Selected(0) = True
' Fill the combo.
strSql = "SELECT tblLogo.IdLogo, tblLogo.NomLogo " & _
"FROM tblLogo ORDER BY tblLogo.IdLogo; "
Me.cboLogoRepas.RowSource = strSql
End Sub
I am completely lost.
Thanks
--
Jac Tremblay


.



.


.
 

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