No vba codes work on form

jdwazere

Registered User.
Local time
Today, 13:25
Joined
Feb 17, 2007
Messages
22
So far on a form I'm using I haven'tbeen able to use VBA code successfully.
I'm not sure why this is happening, maybe there is something wrong with my database?

My recent attempt was to get a textbox to appear visible only when "None" was selected on the combobox next to it.

The code for this was:
Private Sub CboOutletSize_AfterUpdate()
Dim strsize As String
Dim bolquantity As Boolean


strsize = Me.CboOutletSize.Value

If strsize = "None" Then
bolquantity = False
End If

bolquantity = Me.txtOutletQuantity.Visible


End Sub

Before that I tried basing a combo box on another combo box which queries the different sizes of ball valves based on the type of ball valve chosen, but that failed also.
 
And are you certain the correct column of the combobox is the bound column?

Have you tested what's being output from the comboboxes via msgbox or debug.print?
 
The combo boxes are 2 columns wide, but only show first column. Maybe thats why it doesn't work...how can you do an if test on just the first column?
I presume its continuous.
 
The form is continuous if it shows all the records in the recordsource rather than one at a time.

Generally I find it's more for subforms than mainforms, but not exclusively.

Code:
msgbox "Column0: " & CboOutletSize.column(0) & " Column1: " & CboOutletSize.column(1)

I forget if the column counter is 0 based or 1 based, I think it's 0 though.
 
In fact it was a single form, I just guessed.

It said that column0 is the one which I want to test, it said column0 = "none" and column1 is "0".
Column 1 was only used to order the records by size.
 
Guesses don't help when you're asked a question jd.

Are you making a selection from the combo box or typing it in? If you are typing it in you need to move away from box after typing for the code to fire.
 
And just to check the bound column can you do this (should have included that in the last post):

Code:
msgbox CboOutletSize.Value
 
I tried the msg box and it displayed "None", so I don't know how it's not working when I question if it equals that.

Nothing can be entered into the combo box, the combo box just displays the table records, which are fixed.
 
Ok, your code isn't changing the Visible property of any of the controls. You need to assign a True or False value to it. E.g.
Code:
Me.[COLOR=Blue]txtBoxName[/COLOR].Visible = [COLOR=Blue]True[/COLOR]
...will make the textbox visible.
 
I managed to get it working, it was just because I had the 'bolquantity = Me.txtOutletQuantity.Visible' reading the wrong way round.
Thanks for your help with that!

Now while we're here, how can you make these two combo boxes work.

They are both based on a single table.

The first combo box defines which type of ball valve they are whilsed the second picks the sizes of the ball valve that are queried. Here's what I have:

Private Sub lstBVType_AfterUpdate()
Dim strSource As String

strSource = "SELECT Code " & _
"FROM BallValveTable " & _
"WHERE Type = '" & Me.lstBVType & "' ORDER BY Size;"
Me.lstBVSize.RowSource = strSource
Me.lstBVSize = vbNullString
Me.lstBVSize.Requery

End Sub

That is the code in the after update of the first combo box. I could originally get the first one to work.
 
You're talking about cascading combo boxes aren't you?

So what is happening when the code is run? No records are returned or an error is thrown?

Field names like Code, Type and Size are a bad choice because they are reserved keywords, so to make them work in your queries you have to enclose them in square brackets:
Code:
strSource = "SELECT[COLOR=Red] [[/COLOR]Code[COLOR=Red]] [/COLOR]" & _
"FROM BallValveTable " & _
"WHERE [COLOR=Red][[/COLOR]Type[COLOR=Red]] [/COLOR]= '" & Me.lstBVType & "' ORDER BY [COLOR=Red][[/COLOR]Size[COLOR=Red]][/COLOR];"
Also, is the data type of Type Text?
 
Brilliant, that worked.

I don't really know what I did wrong last time.

Thanks again for your help and quick response.
 

Users who are viewing this thread

Back
Top Bottom