If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Loops twice through VBA code

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-11-12, 07:53
marcusmacman marcusmacman is offline
Registered User
 
Join Date: Sep 2010
Location: UK
Posts: 119
Loops twice through VBA code

Hi all,

I'm trying to write code where if i click on the Description field in expands the field to the entire length of the screen. Then if you click it again to returns to the original height.

The problem i have is the code gets executed twice??

So it first goes through the first 'If' statment, updates gbl_int_Clicked by 1 then starts from the top again, see gbl_int_Clicked is 1 so goes to the second 'If' statement!!! arrrrrh. I've tried exit sub at the end of each if statement but no, it insists on executing it twice. Please help :-)

here's the code


Private Sub Description_Click()

If gbl_int_Clicked = 0 Then

Description.Height = 7420
Line15.Height = 7420
Line4.Height = 7420
Line11.Height = 7420
Line45.Height = 7420
Line30.Height = 7420
gbl_int_Clicked = 1


ElseIf gbl_int_Clicked = 1 Then

Description.Height = 400
Line15.Height = 400
Line4.Height = 400
Line11.Height = 400
Line45.Height = 400
Line30.Height = 400
gbl_int_Clicked = 0

End If

End Sub
Reply With Quote
  #2 (permalink)  
Old 01-11-12, 08:22
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
1. You can simplify and spare the global variable:
Code:
Private Sub Description_Click()

    If Me.Description.Height = 400 Then
        Me.Description.Height = 7420
        Me.Line15.Height = 7420
        Me.Line4.Height = 7420
        Me.Line11.Height = 7420
        Me.Line45.Height = 7420
        Me.Line30.Height = 7420
    Else
        Me.Description.Height = 400
        Me.Line15.Height = 400
        Me.Line4.Height = 400
        Me.Line11.Height = 400
        Me.Line45.Height = 400
        Me.Line30.Height = 400
    End If

End Sub
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old 01-11-12, 09:05
marcusmacman marcusmacman is offline
Registered User
 
Join Date: Sep 2010
Location: UK
Posts: 119
that's clever thinking :-) it's worked fine

Out of curiosity is there any reason why my code looped twice?

Also, when i reduce the field back to its original height. The record still stays at the enlarged height.

I basically have a continuous form which shows all the record for an order. When the user clicks on the description field it expands, and when you click again it goes back to the original size. The problem is when it expands, it expands all the descriptions field (which is fine) since they go off the bottom of the screen. When i click again, the description field returns to its original height but the record height stays enlarged. I tried a requery after click but that didn't work. Any ideas appreciated

Last edited by marcusmacman; 01-11-12 at 09:17.
Reply With Quote
  #4 (permalink)  
Old 01-11-12, 10:09
weejas weejas is offline
Registered User
 
Join Date: Sep 2006
Location: Surrey, UK
Posts: 448
Your code looped twice because you changed the state of the control that was referenced in the IF and ELSEIF statements.
__________________
10% of magic is knowing something that no-one else does. The rest is misdirection.
Reply With Quote
  #5 (permalink)  
Old 01-12-12, 07:28
marcusmacman marcusmacman is offline
Registered User
 
Join Date: Sep 2010
Location: UK
Posts: 119
Hi all,

Just to complete the thread. I managed to sus out getting the height of the form back to the original size after i increased the height of the description field. Here is the code.

Private Sub Description_Click()

If Me.Description.Height = 400 Then
Me.Description.Height = 7420
Me.Line15.Height = 7420
Me.Line4.Height = 7420
Me.Line11.Height = 7420
Me.Line45.Height = 7420
Me.Line30.Height = 7420

Else
Me.Description.Height = 400
Me.Line15.Height = 400
Me.Line4.Height = 400
Me.Line11.Height = 400
Me.Line45.Height = 400
Me.Line30.Height = 400
Me.Detail.Height = 400

End If


End Sub
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On