Results 1 to 8 of 8
  1. #1
    Juan4412 is offline Competent Performer
    Windows 7 Access 2002
    Join Date
    Dec 2010
    Posts
    209

    VBA Code not working how it Should

    Here is what I be needing:


    I have a tickbox, and I am wanting it to disable the tickbox if you check it, but disable it after the "Add Record" button has been pressed. I set it up by uing the AfterUpdate feature of the tickbox, but it is locking as soon as I check the box, not once the "Add Record" button is pressed. The Visaul Basik code that I used was:

    Code:
     
    Private Sub Check146_AfterUpdate()
    If Me.Check146 = True Then
    Me.Check134.SetFocus
    Me.Check146.Enabled = False
    Me.Check144.Enabled = False
    Me.Check148.Enabled = False
    
    Else
    
    Me.Check144.Enabled = True
    Me.Check146.Enabled = True
    Me.Check148.Enabled = True
    
    End If
    End Sub
    I also tried to set it up on the AfterClick() on the "Add Record" button, but this wouldn't even allow the record to lock.

    I really want the code to read:
    Code:
    If Me.Check146 And Me.Check144 = True Then....
    But when I tried this code, the Debugger gave no error, but Access would not disable any fields at all?

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you logic is confusing.
    when you said: "and I am wanting it to disable the tickbox if you check it, but disable it after the "Add Record" button has been pressed", which case do you want to disable the tickbox.

    in you code, you put "Me.Check146.Enabled = False" when the checkbox is checked. of course "it is locking as soon as I check the box". if you don't what disable it here, please remove the code to the click event of "Add Record" button.

    Also please note that disabled is different from locked.

  3. #3
    Juan4412 is offline Competent Performer
    Windows 7 Access 2002
    Join Date
    Dec 2010
    Posts
    209
    I am wanting to disable the tickbox, but only after the "add record" button has been pressed.

    So if I move this code to the "add record" event it will do as I wish?

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you can move it to the click event of "add record" button

  5. #5
    Juan4412 is offline Competent Performer
    Windows 7 Access 2002
    Join Date
    Dec 2010
    Posts
    209
    Code:
    Private Sub Form_AfterUpdate()
    Dim c As Control
    If Flag_Locked = True Then
    
    Me.Flag_Locked.Enabled = False
    Me.Name_First.Enabled = False
    Me.Name_Last.Enabled = False
    Me.ID.Enabled = False
    Me.Cmd_Delete_Record.Enabled = False
    
    Next
    
    Else
    
    Me.Flag_Locked = False
    
    Next
    
    Me.Flag_Locked.Enabled = True
    Me.Name_First.Enabled = True
    Me.Name_Last.Enabled = True
    Me.ID.Enabled = True
    Me.Cmd_Delete_Record.Enabled = True
    
    End If
    
    End Sub
    mofycatyns were made to mi code and it is somewaht functioning how me need it. But when I click the "Add Record" button it is locking the next record too. I only needs it to lock the record I just added. What wrong with mi code?

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you can't lock only one record. all properties(locked, color, and other format) of a column control affect all records.

  7. #7
    Juan4412 is offline Competent Performer
    Windows 7 Access 2002
    Join Date
    Dec 2010
    Posts
    209
    I be just wanting to no allow edits on the record that was just added, once the add button i smashed. I add a "unlock" button on form that if you push it unlock to allow edits, but once the "add record" buton be mashed I want to no allow edits, that what I try to accomplish.

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    if you want to lock only the new added record, use code in CURRENT event of the form. check if current row is the new one. if is, lock the fields; if not, unlock.

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

Similar Threads

  1. VBA Code Not working
    By jo15765 in forum Programming
    Replies: 12
    Last Post: 12-03-2010, 04:01 PM
  2. Code for change PW frm not working(ish)
    By Desstro in forum Programming
    Replies: 4
    Last Post: 12-02-2010, 02:50 PM
  3. DLookup code not working
    By lukekelly in forum Programming
    Replies: 9
    Last Post: 06-15-2010, 06:08 AM
  4. VB code not working
    By cwwaicw311 in forum Programming
    Replies: 17
    Last Post: 04-26-2010, 07:02 PM
  5. VBA Code for working with IE
    By smikkelsen in forum Programming
    Replies: 3
    Last Post: 04-15-2010, 01:05 AM

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