Results 1 to 13 of 13
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    VBA Code Not working

    I may not be typing the code correctly, but I am wanting my two fields on my form to be disabled when the checkbox is checked, and then enable the fields when the checkbox is not checked or unchecked. The VBA code I am using is:



    Code:
    Private Sub Flag_Lock_box_Click()
    Dim c As Control
    If Me.Flag_Lock_box = Yes Then
    Me.Flag_Lock_box = True
    
    Me.Name_First.Enabled = False
    Me.Name_Last.Enabled = False
    End If
    
    If Me.Flag_Lock_box = No Then
    Me.Flag_Lock_box = False
    
    Me.Name_First.Enabled = True
    Me.Name_Last.Enabled = True
    End If
    
    End Sub
    And it works for locking the record when the checkbox is checked, but it disables the checkbox so I can not "uncheck" the box if editing is needed. What modification do I need to make in order to be allowed to uncheck the box and modify the record, if needed?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try the following:
    Code:
    Private Sub Flag_Lock_box_Click()
       If Me.Flag_Lock_box Then
          Me.Name_First.Enabled = False
          Me.Name_Last.Enabled = False
       Else
          Me.Name_First.Enabled = True
          Me.Name_Last.Enabled = True
       End If
    End Sub

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    This code works, and I tried to add to it, and this is the code that I added:

    Code:
    Private Sub Validation_flag_passed_Click()  
       If Me.Validation_flag_passed Then  
          Me.Flag_validated_only_Labs.Enabled = False  
          Me.Flag_validated_only_Documents.Enabled = False 
         Me.Name_First.Enabled = False 
          Me.Name_Last.Enabled = False
    
    
       Else  
          Me.Flag_validated_only_Labs.Enabled = True  
          Me.Flag_validated_only_Documents.Enabled = True 
         Me.Name_First.Enabled = True
          Me.Name_Last.Enabled = True
    
       End If  
    End Sub




    The issue I am running into is when I debug I get this error,

    Compile Error:
    Method or Data member not found



    And it is highlighting the .Enabled on my two new ones (the ....documents, and the ...labs) that I am adding. Any suggestions on why this is occuring?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    When you use the period "." as the connector then intellisense should kick as soon as you press the "." and show you the possible choices. Does it and have you spelled the control names correctly? Those *are* valid control names right? Are they bound to fields of the same name so Access has trouble determining which you want? Chanve the name of the control by prepending a txt on the front and see what happens.

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    sometimes intellisense stops working if there is memory that hasn't been destroyed. compile errors like that can also happen if there are broken library references in the vba project. may want to check those as well.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    As is usually my style, when weird things begin to happen I recommend *importing* the db into a fresh, new db and see if the problem follows. http://www.btabdevelopment.com/ts/impnew
    You might also want to make sure name AutoCorrect is turned off. http://allenbrowne.com/bug-03.html

  7. #7
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    I have the name and the control source set as the same I also have the field on my table (I think that means it is bound). I had to set these the same because if I didn't they would not display when I went to the VB Editor.

    I don't think exporting the table would be a viable option...in this instance I am using some VBA programming that someone else did, I am just adding to what they already did, and I don't want to loose that. Unless, there is a way to extract the code as well, but I think that would bring the errors with it.

    Yes the intellisense is working, when I type:

    Me.Flag_(it shows all of the items I have that begin with this), but when I hit
    the "." Enabled does not display as an option (probably why I got the error!!)

    I have tried googling what the error means, but it's no help on this case!

  8. #8
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Is the field you're trying to do the .Enabled on the label field 'name' or the text box field 'name'? A label field doesn't have the Enabled property but it's easy to name a label as the field instead of the actual text box. If the Intellisense shows .Enabled when typing in a different field name but doesn't on the Flag_validated_only_Labs as you type, I would check on the form to make sure that Enabled is a property for that field itself (ie. select Flag_validated_only_Labs in the combobox in the upper left corner of the properties popup and then see what field is actually selected on the form). If the label field is selected instead of the text box field, this would be the problem.

    Otherwise if the Intellisense doesn't show the .Enabled for 'any' fields as you type, I'd check your references as ajetrumpet suggested (Tools->References while in the coding window). If any show as 'missing', this would be the cause.

    Or I'd comment out this code, then Debug->Compile the code and then try again. Sometimes (although rare) if you haven't done a good compile on the code, this can affect other coding. Or you run out of memory as ajetrumpet suggested (which is also rare but possible - re-open the mdb holding the shift key to bypass any code which would eat up all the memory). If this was the case though, you wouldn't see the intellisense .Enabled for any vba coding for any fields.

    You could also import just the table and form (for troubleshooting) into a new mdb and try it if you can't fully import all the objects.

    Usually though it's something as simple as a mis-spelling of the field name in the code to what the 'Name' property of the TEXT box field itself (not the label 'Name' property) is on the form (you can stare at a name for hours and type it over and over again but it's slightly different or is the Name of the label and not the Text box field). Especially if intellisense works for other fields which would only leave spelling or wrong field as the problem (which would cause the Method or Data member not found error when compiling). It would be easy to mis-type a _ in as the field name (one reason why I prefer not to use _ in any of my field names.) Try changing the 'Name' property of the Text box field on the form to something without a _ and then try the code again. (note: you can also highlight the wording in the 'Name' property in the properties popup and then do a copy and then paste it in code.)

    Unless you have a corrupt form/mdb, there's really nothing else that would cause the problem.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by jo15765 View Post
    I don't think exporting the table would be a viable option...in this instance I am using some VBA programming that someone else did, I am just adding to what they already did, and I don't want to loose that. Unless, there is a way to extract the code as well, but I think that would bring the errors with it.
    If you follow the link I provided you will see it shows how to *IMPORT* your db into a new, empty db - not export from the old one. It only takes a minute or twi and the code follows just not the corruption, if there is any.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by jo15765 View Post
    I have the name and the control source set as the same I also have the field on my table (I think that means it is bound). I had to set these the same because if I didn't they would not display when I went to the VB Editor.
    They do not need to be named the same and it works just fine. If you rename a control then you will need to move the code to the new event. Copy and paste works just fine for this just don't copy the Private Sub or End Sub lines.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by jo15765 View Post
    Yes the intellisense is working, when I type:

    Me.Flag_(it shows all of the items I have that begin with this), but when I hit
    the "." Enabled does not display as an option (probably why I got the error!!)

    I have tried googling what the error means, but it's no help on this case!
    Rename this control txtFlag and then see what Intellisense does. I'll bet Access is confused and has selected the Field in the table instead of the control. Fields do not have an Enable property but controls do.

  12. #12
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    I named the tickbox one name, and the text box another name and that corrected it! I didn't know that it could potentially confuse access if you have both the same name, but it makes sense!

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Since this is the default for Access it simply is putting a time bomb in your application. Are you ready to use the Thread tool and mark this thread as Solved?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Login/Password Code not working
    By eww in forum Programming
    Replies: 3
    Last Post: 09-21-2010, 10:49 AM
  2. DLookup code not working
    By lukekelly in forum Programming
    Replies: 9
    Last Post: 06-15-2010, 06:08 AM
  3. VB code not working
    By cwwaicw311 in forum Programming
    Replies: 17
    Last Post: 04-26-2010, 07:02 PM
  4. VBA Code for working with IE
    By smikkelsen in forum Programming
    Replies: 3
    Last Post: 04-15-2010, 01:05 AM
  5. Replies: 4
    Last Post: 05-12-2009, 01:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums