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
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.
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.
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.
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.
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
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.