VB Help!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good day,

I am trying to write code to get a sub form table to recogninze the main
table and performe a calculation based on a field. I am using lost focus

Baically My input table (Input_Tbl) is the table I use for inputing standard
information for a record. I have then created another table for my subform
(Output_Tbl) which the related to the Input tbl by the ID (One to Many).

what I want to do is when a field say for example Machine type (MACTYPE) =
1034 in my sub_tbl in another field in the sub_tbl (example PCSHR) to
calculate and return a value based on using a field in the Input_tbl. The
code I write is
Private Sub MACTYPE_LostFocus()

If MACTYPE = "1034" Then

PCSHR = input_tbl.[Length] * 2

Else

PCSHR = 0

End If

End Sub

And it does not work. Please Help. Thanks Kyle.
 
First, why are you trying to store a value that you can calculate? Just
calculate it when it's needed.

Now, to refer to the control on the main form, the syntax to refer to a
control on a main form from VB in the subform is:

Me.Parent.ControlName
 
The reason I want to store the value is because I want to be able to print a
report. and be able to recall the information.

Thanks for the syntax but after trying and trying I got it to work. I did
the following.

Private Sub MACTYPE_LostFocus()

'Soco Saw Test
If MACTYPE = 1034 Then
PCSHR = (LENGTH) * 2

'Round Polisher
ElseIf MACTYPE = 1042 Then
PCSHR = (LENGTH) * 1

Else

PCSHR = 0

End If

End Sub

Not sure if this is correct but it works.

Thanks for youre reply.

Wayne Morgan said:
First, why are you trying to store a value that you can calculate? Just
calculate it when it's needed.

Now, to refer to the control on the main form, the syntax to refer to a
control on a main form from VB in the subform is:

Me.Parent.ControlName

--
Wayne Morgan
MS Access MVP


K said:
Good day,

I am trying to write code to get a sub form table to recogninze the main
table and performe a calculation based on a field. I am using lost focus

Baically My input table (Input_Tbl) is the table I use for inputing
standard
information for a record. I have then created another table for my subform
(Output_Tbl) which the related to the Input tbl by the ID (One to Many).

what I want to do is when a field say for example Machine type (MACTYPE) =
1034 in my sub_tbl in another field in the sub_tbl (example PCSHR) to
calculate and return a value based on using a field in the Input_tbl. The
code I write is
Private Sub MACTYPE_LostFocus()

If MACTYPE = "1034" Then

PCSHR = input_tbl.[Length] * 2

Else

PCSHR = 0

End If

End Sub

And it does not work. Please Help. Thanks Kyle.
 
Back
Top