form event handler (1 Viewer)

youyiyang

Registered User.
Local time
Today, 08:38
Joined
Apr 7, 2009
Messages
49
Hi!
I made a access database for recording PC repairing information for my neighbours. I use a form named Customer to store my neighbours' information while use its subform named Problem_Solving to store maintenance records. What I want to do is to show the subform, Old_PC_Configuration_x and New_PC_Configuration_x, which are also the subform of subform Problem_Solving when I open the Problem_Solving. There is a field called computers to control how many subform, Old_PC_Configuration_x and New_PC_Configuration_x, which mean the configurations of neighbours' computers and are also the subform of Problem_Solving, should be displayed. The program is as follows:
Code:
Private Sub Form_Open(Cancel As Integer)
Dim i, j As Integer
Dim k As String
Dim objDB As Database
Dim objRS As Recordset
Me.ID.SetFocus
k = ID.Text
Set objDB = CurrentDb()
Set objRS = objDB.OpenRecordset("select * from Problem_Solving where ID=" & k, dbOpenDynaset)
MsgBox "select * from Problem_Solving where ID=" & k
'MsgBox objRS.Fields("Computers")
j = 1
If IsNull(objRS.Fields("Computers")) Then
    i = 1
Else
    i = CInt(objRS.Fields("Computers"))
End If
Do While j <= 5
     If j <= i Then
        Me.Controls("Old_PC_Config_" & j).Visible = True
        Me.Controls("New_PC_Config_" & j).Visible = True
     Else
        Me.Controls("Old_PC_Config_" & j).Visible = False
        Me.Controls("New_PC_Config_" & j).Visible = False
     End If
     j = j + 1
Loop
End Sub
Now the question is what form event handler should I choose everytime I open the Problem_Solving? form_open? form_load? form_activate? form_beforequery? form_gotfocus? Most of them only triger the event once while I expect everytime I open the Problem_Solving then the computers' configuration subform would be correctly displayed.

Any ideas would be very appreciated!

Maybe my access database is too complicated to be devised. I just use subform embeded in subform skill to devise this database since I have long time not contact access. What I want to do is when I click the subform Problem_Solving in the form Customer, subform Computer configuration would be displayed according to a field in Problem_Solving. For example, there are 3 PCs in one's family, then 3 old PC configurations and 3 new PC configurtions after maintenance would be displayed. Since the numbers of PCs in each family is different, so different PC configurations would be showed according to the field computers. The program trigger time is just when I open Problem_Solving. I just wonder which event handler would be used. I tried form_load, form_open, form_activate, form_beforerender,form_gotfocus, but the program only runs once after I click the Prolem_Solving. If I choose another Problem_Solving in another Customer, the program would not be trigered probably because the form had been opened already. This will lead to display too many or too little PCs regarding to his own PC numbers when I open another form Customer.

Thanks.
 

HiTechCoach

Well-known member
Local time
Yesterday, 19:38
Joined
Mar 6, 2006
Messages
4,357
IK an not sure that I understand what you are trying to do. Maybe explain in plain English (not database terms) what you are wanting.

I think you may be wanting to link sub forms together. If this is ture, then you would use the On Current event of the first sub form to requery the second sub form.
 

youyiyang

Registered User.
Local time
Today, 08:38
Joined
Apr 7, 2009
Messages
49
What I want to do is to show how many PC configurations when I open a form.
I am working to solve PC problems for my neighbours. So I decide to make an access database to collect all the informaton, including customers, their PC configurations and the solutions I did, to the database. Each time I open the customer information form, I just want know how many PC configurations before repairing and after repairing he has.
So, when I open a form, I expect to see the specific PC configurations. But when I open another form, the PC configurations do not change. Therefore I program a little code to do that but I do not know where to put it.
This is my problem.
 

HiTechCoach

Well-known member
Local time
Yesterday, 19:38
Joined
Mar 6, 2006
Messages
4,357
I am working to solve PC problems for my neighbours.
:confused: I am not sure what this means.

Without knowing more about the database design, it will be hard to say exactly where to put the code. As previously stated, my guess is that you will need to use the On Current event.

It may help if you will post a sample of your database. If you do, I should probably be able to help you get it working.
 

youyiyang

Registered User.
Local time
Today, 08:38
Joined
Apr 7, 2009
Messages
49
Ok. I am just working for my community to repair PCs for my neighbours. I attach my database here so you can check it.
 

Attachments

  • pc_customers.mdb
    580 KB · Views: 108

youyiyang

Registered User.
Local time
Today, 08:38
Joined
Apr 7, 2009
Messages
49
Thank you so much HiTechCoach!
You are right. When I put my code into the current event handler it works.
As msdn says:
"This event occurs both when a form is opened and whenever the focus leaves one record and moves to another."
I just want to change the subform to be visible and invisible when I move one record to another. I have searched so many events - open, load, activate, but not current.
 

Users who are viewing this thread

Top Bottom