Results 1 to 4 of 4
  1. #1
    rwahdan1978 is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    57

    form not updated after showing form again

    Hi,

    I have a form that has a textbox which display score of 0, I have a button, when clicked another form is open (the current form is hidden not closed). The second form has a button, when clicked it is assigning a global variable a value (say 100) then closes the 2nd form and make the first one visible again. Now, the textbox (at the start) had value of 0 and it is takijg the value of the global variable which should show 100 but it is not showing that. if i close the form and open again it is showing the 100. How to do it without closing and opeining the form?

    form1 (on load)


    Code:
    Me.ahmad.Text = Module1.AhmadScore 'global variable
    form1 (button click)
    Code:
    Private Sub ahmad100_Click()
        
        Me.ahmad200.Visible = True
        Me.ahmad200.SetFocus
        Me.ahmad100.Visible = False
        
        DoCmd.OpenForm "form1"
        Me.Visible = False
    
    
    End Sub
    form2
    Code:
    Private Sub Command5_Click()
        If (Module1.AhmadScore = 0) Then
        
            DoCmd.OpenQuery "updateAhmad"
            Module1.AhmadScore = 100
            DoCmd.Close acForm, "form1"
            Forms![main].Visible = True
        
        ElseIf (Module1.AhmadScore = 100) Then
        
            DoCmd.OpenQuery "updateAhmad"
            Module1.AhmadScore = 300
            DoCmd.Close acForm, "form1"
            Forms![main].Visible = True
        
        End If
        
    End Sub

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Whenever changing the global variable, assign the new value to the form1 textbox

    Code:
            Module1.ahmadScore = 100
            Forms("form1").ahmad = ahmadScore
    Also in the form load event don't use the .text property, just

    Me.ahmad = Module1.ahmadScore

  3. #3
    rwahdan1978 is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    57
    Quote Originally Posted by davegri View Post
    Whenever changing the global variable, assign the new value to the form1 textbox

    Code:
            Module1.ahmadScore = 100
            Forms("form1").ahmad = ahmadScore
    Also in the form load event don't use the .text property, just

    Me.ahmad = Module1.ahmadScore
    Thanks it worked

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Quote Originally Posted by rwahdan1978 View Post
    Hi,

    I have a form that has a textbox which display score of 0, I have a button, when clicked another form is open (the current form is hidden not closed). The second form has a button, when clicked it is assigning a global variable a value (say 100) then closes the 2nd form and make the first one visible again. Now, the textbox (at the start) had value of 0 and it is takijg the value of the global variable which should show 100 but it is not showing that. if i close the form and open again it is showing the 100. How to do it without closing and opeining the form?

    form1 (on load)
    Code:
    Me.ahmad.Text = Module1.AhmadScore 'global variable
    form1 (button click)
    Code:
    Private Sub ahmad100_Click()
        
        Me.ahmad200.Visible = True
        Me.ahmad200.SetFocus
        Me.ahmad100.Visible = False
        
        DoCmd.OpenForm "form1"
        Me.Visible = False
    
    
    End Sub
    form2
    Code:
    Private Sub Command5_Click()
        If (Module1.AhmadScore = 0) Then
        
            DoCmd.OpenQuery "updateAhmad"
            Module1.AhmadScore = 100
            DoCmd.Close acForm, "form1"
            Forms![main].Visible = True
        
        ElseIf (Module1.AhmadScore = 100) Then
        
            DoCmd.OpenQuery "updateAhmad"
            Module1.AhmadScore = 300
            DoCmd.Close acForm, "form1"
            Forms![main].Visible = True
        
        End If
        
    End Sub
    Look at your code.
    Whenever you are duplicating code, there usually is a better way.

    Code:
    Private Sub Command5_Click()
        DoCmd.OpenQuery "updateAhmad"
        If (Module1.AhmadScore = 0) Then
            Module1.AhmadScore = 100
        ElseIf (Module1.AhmadScore = 100) Then
            Module1.AhmadScore = 300
        End If
        DoCmd.Close acForm, "form1"
        Forms![main].Visible = True
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 6
    Last Post: 11-19-2017, 04:51 PM
  2. Replies: 9
    Last Post: 08-08-2016, 02:57 PM
  3. Replies: 11
    Last Post: 04-09-2016, 08:54 PM
  4. Showing Changes in Updated Data
    By Ddempsii in forum Reports
    Replies: 10
    Last Post: 12-10-2015, 09:03 AM
  5. Replies: 3
    Last Post: 06-04-2014, 10:54 AM

Tags for this Thread

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