Results 1 to 5 of 5
  1. #1
    ihateaami is offline Novice
    Windows 98/ME Access 2003
    Join Date
    May 2009
    Posts
    2

    VBA code is not working with a change of record

    I have the following VBA code

    Private Sub Form_Open(Cancel As Integer)
    If Me.Text25 = "Theme" Then
    Me.Text53.Visible = True
    Me.Label54.Visible = True
    Else
    'MsgBox (test)
    Me.Text53.Visible = True
    Me.Label54.Visible = True
    End If


    End Sub

    This code works fine when the form initially opens. However when I select another record I want the code to look at the value in textbox 25 and make textbox 53 visible if the value in textbox 25 has the text value Theme.

    I have tried a number of ways to get this to work including putting the code in other areas and using me.requery.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Two points. The Open event is too early in the process to reference a control on a form so you would need to use the OnLoad event. The other point is your code belongs in the Current event of the form so it executes every time you go to a new record, including the 1st time.

  3. #3
    ihateaami is offline Novice
    Windows 98/ME Access 2003
    Join Date
    May 2009
    Posts
    2
    thanks, that works now. The code I initially attached also has some errors it should be

    Code:
    Private Sub Form_Open(Cancel As Integer)
       If Me.Text25 = "Theme" Then
          Me.Text53.Visible = True
          Me.Label54.Visible = True
       Else
          Me.Text53.Visible = False
          Me.Label54.Visible = False
       End If
    End Sub

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Glad we could help and I added [ code ] tags to your post to show how it helps the post. Try the link in my sig.

  5. #5
    Egemen is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2008
    Posts
    2
    try to write tis code in Form Current event.

    Me.Text53.Visible = (me.text25="Theme")
    Me.Label54.Visible = (me.text25="Theme")

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

Similar Threads

  1. 07 Switchbox Not Working! - please help
    By techexpressinc in forum Access
    Replies: 16
    Last Post: 05-05-2009, 09:36 AM
  2. Why isn't this working?
    By adiecidue in forum Queries
    Replies: 4
    Last Post: 04-27-2009, 10:29 AM
  3. Simple Nav Form Code Not Working
    By alsoto in forum Forms
    Replies: 10
    Last Post: 04-10-2009, 09:30 AM
  4. If name = test1 then let , NOT WORKING ?
    By caljohn527 in forum Forms
    Replies: 3
    Last Post: 01-21-2009, 04:01 PM
  5. Replies: 1
    Last Post: 08-10-2008, 01:09 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