Form Reload when closing a different form

sammy204

Registered User.
Local time
Today, 10:30
Joined
Jun 14, 2008
Messages
20
Hi,

I have 2 forms

On the 1st form I have a form_load event running some vb code

on the 2nd form I want to be able to close the form and rerun that vb code. I know the code to close the 2nd form, but not to refresh the load event on 1st form. By the way I want the 1st form to remain open the whole time.
 
Just call the procedure. That's all it is (you may have to set focus to the first form first though):
Code:
Call YourFormEvent name here
 
Hi Thanks but I dont think it works

The code i want to run is on the first form. I want to be able to close the second form and run this code from the second form. This is in Access 07 by the way.

So where should I put the call form_load code?

Thanks
 
Hi

as ajetrumpet suggessted you can reuse the code of your first form by simply call it. Regarding where to put it you can create a button which closes your form and put the form there, so that the customised button will run the code you wish and also closes your second form.
 
You don't say what kind of vb code you're running, but might try this, depending on what the code does. Move the pertinent code from the Form_Load event in Form1 to the Form_Activate event of Form1. The Form_Activate event runs immediately after the Form_Load event, and it will automatically run again when Form2 closes and focus returns to Form1.

As I say, may work, depending on the purpose of the code you're running.
 
Hi thanks guys that works perfectly now.

Sorry I don't know what VB Code I'm running, only that it is Microsoft visual basic which runs with Microsoft access 2007.

Thats the first problem solved, just one more:

I have 10 text boxes and instead of writing the same code for each one 10 times, I wondered if i can run the same code on each one with a for statement. Each textbox has the same code run on it.

I was thinking of something like:

For number = 1 to 10
If me.textbox(number).value = blah blah Then
blah blah
end if
next


but this doesent work

Any Ideas?
all the textboxes have the same name of textbox, followed by a number 1 to 10. e.g. textbox1,textbox2,textbox3,textbox4

etc
 
try setting your textboxes tag property to ctrlset and then use something like the following

Code:
Dim ctrl As Control

For Each ctrl In Me.Controls
        
       If ctrl.Tag = "CtrlSet" Then
         'blah blah
       End If
    
 Next ctrl
 
Hi Thanks but I use the number of the textbox more than once. The code is:

DoCmd.GoToRecord , , acGoTo, 1
If Me.textbox1.Value = "Ordering" Then
Me.label1.BackColor = vbGreen
Else
Me.label1.BackColor = vbBlue
End If

and the same for textbox 2 except all the 1s are now changed to 2s


thats why with the other code with a for num = 1 to 10 i could put something like:


DoCmd.GoToRecord , , acGoTo, num
If Me.textbox(num).Value = "Ordering" Then
Me.label(num).BackColor = vbGreen
Else
Me.label(num).BackColor = vbBlue
End If


Hope that makes sense, Thanks again
or will that work with the ctrlset bit? I dont think it wil
 
sammy204 said:
Sorry I don't know what VB Code I'm running, only that it is Microsoft visual basic which runs with Microsoft access 2007.

If you don't know what code you're running, how could you possibly know that you need to run it again, after closing your second form? To be honest, your original post sounded kind of funny; code in the Form_Load event very seldom is something that needs to be run more than once.

I'm not saying this to be picky, but out of genuine curiosity.
 
Hi about the not sure what code Im running, I thought the person was asking the like type of vb code because he asked what kind is it. So I thought maybe theres different types of visual basic.

And it was in the form load because its a form with some coloured labels representing the different statuses of an order. So when the form loads, I wanted it to display the right colours, and when the second form is opened, a status is changed and the form is closed, I wanted it to update the first form by running the code in the form load of that first form and changing the colour.

Hope that makes sense lol

But anyway any ideas on how to do that piece of code I asked about in the last post?
 

Users who are viewing this thread

Back
Top Bottom