probably a simple question regarding combo box

robvr6

Registered User.
Local time
Today, 04:50
Joined
Sep 27, 2005
Messages
23
Hi all,

Im back again for more advice. What it is I hava a combo box yes/no and I was wondering how to disable and enable a button depending on if yes or no is selected. Hope someone can help

thanks
J
 
J,

Use a CheckBox instead, for example cbxMyCheckBox.

In its OnClick Event, put the following [Event Function]

Code:
If cbxMyCheckBox Then
   Me.cmdMyCommandButton.Enabled = False
Else
   Me.cmdMyCommandButton.Enabled = True
End If

Wayne
 
can it not be doene using the yes no because it needs to go int the table as yes or no

thanks
J
 
J,

If it really must be the text words "Yes" and "No", then
use the AfterUpdate event of your bound combo:

Code:
If Me.cboYourCombo = "Yes" Then
   Me.cmdMyCommandButton.Enabled = False
Else
   Me.cmdMyCommandButton.Enabled = True
End If

Wayne
 
for some reason my button isn't becoming inactive/disabled???
 
J,

Did you use the name of "your" combobox in the code?

Do you know the value of "your" combobox? Can you use the debugger?

Is "your" combobox multi-column?

Wayne
 
Also.... did you put in the Click event for the Yes/No cbo box...


Private Sub cboYesNo_AfterUpdate()
If cboYesNo.Value = "Yes" Then
cboMyBox.Enabled = True
Else
cboMyBox.Enabled = False
End If
End Sub
 
Thanks I got it working using this code

Code:
If Me.cboYourCombo = "Yes" Then
   Me.cmdMyCommandButton.Enabled = False
Else
   Me.cmdMyCommandButton.Enabled = True
End If

but if I select no it disables the button but if I then select yes it stays disabled - any ideas anyone?

thanks
J
 
no sorry what I meant to say was that It needs to be disabled on yes but when I click no it enables the button, but if i change it again to yes it ill not disable it again is there something else I need to add.

thanks
J
 
J,

Can you post the DB?

Tools --> Compact/Repair, then ZIP & attach.

Wayne
 
here it is - I am getting confused with it now - Its my first database so you will probably notice other errors Ive made but what I am trying to acheive now is to allow CV documents to be affed for employees because I have a view cv button but if there is not a cv present It throws up errors so I thought it would be easier for me to just disable the button if there is no cv there. I have a yes / no option for cv on record. hope you understand me and thanks for taking time to help me.

J
 

Attachments

J,

Use that same code:

Code:
If Me.Combo63 = "Yes" Then
   Me.cmdOpen.Enabled = False
Else
   Me.cmdOpen.Enabled = True
End If

But put it in the FORM's OnCurrent event. The combo box isn't really being
updated, so the BeforeUpdate event doesn't fire. The form's OnCurrent
event will fire on every record displayed.

Wayne
 
I still can't get this to enable and disable depending on if yes or no is selected - is there any chance you could show me an example on that attached file.

Thanks

J
 
J,

Your ComboBox has a list of values "Yes";"No".

Its format is set to Yes/No. That means that it has a value of EITHER
0 or -1. It will NEVER be equal to "Yes" or "No".

Keep the code in the OnCurrent event, but remove the format specification
for the ComboBox.

Wayne
 
Still no joy with this it changes once but if I then change it again it stays disabled - I thought this was going to be the easy part of building the database lol
 
The code also needs to be in the AfterUpdate event of the combo box [and the OnCurrent event].
 
I think Im gonna try and go with checkboxes because from reading up on them I think I understand them a little better for the purpose I want. Im still struggling to get the result I want so maybe I have been trying to go too advanced with this bieng my first database after all.
 
I downloaded your db1.mdb file, fixed it [and more] and attached my db2.mdb version. Below are the hi-lites as to what I did. I copied your frmEdit form and fixed the problems in my frmEdit-ghudson form. Enjoy!

Change the name of the combo box in question to cbCurrentCVOnFile [as I said before in your other post... remember to use a naming convention with your objects!].

Changed the Limit To List property in the cbCurrentCVOnFile to YES. What if some wise guy keyed a SO WHAT text value in your combo box? My change will prevent that.

Removed the code you had in the combo boxes BeforeUpdate event.

Added this code to the cbCurrentCVOnFile AfterUpdate event and the forms OnCurrent event so the View CV will correctly be enabled if the value is -1 [yes] or not be nabled if the value is 0 [no]

Code:
    If Me.cbCurrentCVOnFile = 0 Then 'combo box = NO
       Me.cmdOpen.Enabled = False
    Else
       Me.cmdOpen.Enabled = True
    End If

Replaced the outdated "wizard" DoCmd.DoMenuItem code with the appropriate DoCmd.RunCommand code in the cmdDel_Click() event and the cmdFind_Click() event.

Corrected the code in the cmdClose_Click() event so that it would close the current form. DoCmd.Close is to vague.

I renamed the FilePath text box to tbFilePath. Remember to use a naming convention with your objects. In code VBA would not always know if you were referring to the table field FilePath or the text box FilePath.

Your command was dying if the tbFilePath field was empty. I added code to test if the tbFilePath field was Null or an empty string.

You need to turn on the "Option Explicit" switch in your modules to help you catch some of the common mistakes we make when not declaring our variables.

The top of each module should have...
Option Compare Database
Option Explicit

I updated your error handlers to also include the error number which you will need to know if you have to trap for a specific error number. Now they look like this...
MsgBox Err.Number & " - " & Err.Description

You method to open a specific file type was kinda funky since you will not know what the user has selected as the default program they prefer to use for specific files. Also they might not have some programs installed. I have imported the code I like to use to open a file. I prefer the ShellExecute method for it also does not have the same problems that the Shell() function sometimes has on certain computers and also if the file path or name has a space in it.

I also imported in my Browse() function to allow the user to click and choose the location of a file. Much better than allowing a user to freely hand type the location and path. To ensure they use the Browse button I locked the tbFilePath text box. You should then be able to remove the basOpenDialogue module and code if you instead use my dBrowseFiles module and code.

Check out my Browse [Find a directory or file] sample for more goodies and a working sample on how I use the ShellExecute method and my Browse function for searching for files and directories and a whole lot more.

I turned off the forms Record Selector property.

Personally I think that you should do away with tracking if a CV file is on file [yes or no in a combo box]. Instead I would check if the tbPathFile is Null. If there is no \path\file\ info in the tbPathFile text box then you would know that there is not a CV file is on file. Or you should check to ensure that the tbPathFile is not Null if the user has selected Yes in the Current CV on File combo box.

I am glad to see that my formula in the tbAge text box is working as I expected.

I know this might seem like a lot but I hope that you agree with what I have done and the methods I used.

Good luck!
 

Attachments

Users who are viewing this thread

Back
Top Bottom