You have
Code:
Private Sub btnCalc_Click()
Dim cablen As Integer '<<<<--- Not needed/ Shouldn't be there
Me.txtHLen = cablen '<<<<--- This is the name of a function, but you are NOT entering the required arguments!
End Sub
Provided these are the names of controls on a form: "Size, P_lgth, Fl_Qty, Vlv_F150_Qty, Vlv_F300_Qty", The button click would be
Code:
Private Sub btnCalc_Click()
Me.txtHLen = cablen(Nz(Size, 0), Nz(P_lgth, 0), Nz(Fl_Qty, 0), Nz(Vlv_F150_Qty, 0), Nz(Vlv_F300_Qty, 0))
End Sub
Be aware that "Size" is a reserved word in Access and shouldn't be used as an object name.
It also looks like you have repeating fields : "Vlv_F150_Qty, Vlv_F300_Qty".
The function (rearranged/rewritten) would be something like:
Code:
Public Function cablen(Dp As Single, lp As Single, nf As Integer, Nvf1 As Integer, Nvf3 As Integer) As Single
On Error GoTo exitsub
Dim Ap As Single
Dim Af As Single
Dim Avf1 As Single
Dim Avf3 As Single
Dim strAllow As String
Dim RsAllow As DAO.Recordset
Debug.Print Dp, lp, nf, Nvf1, Nvf3
'set default return value
cablen = 0
strAllow = "select p_allow, Vlv_F150, Vlv_F300, fl, from tb_pipeallow where abs(p_size-" & Dp & ")<1e-5" '<< I'm not sure about this SQL - think it will error
Debug.Print strAllow
Set RsAllow = db.OpenRecordset(strAllow)
If RsAllow.BOF And RsAllow.EOF Then
MsgBox ("No data selected from tb_pipeallow")
Else
Ap = Nz(RsAllow.Fields("p_allow"), 0)
Af = Nz(RsAllow.Fields("Fl"), 0)
Avf1 = Nz(RsAllow.Fields("Vlv_F150"), 0)
Avf3 = Nz(RsAllow.Fields("Vlv_F300"), 0)
cablen = (Ap * lp + Af * nf + Avf1 * Nvf1 + Avf3 * Nvf3)
End If
RsAllow.Close
Set RsAllow = Nothing
Debug.Print Ap, Af, Avf1, Avf3
Exit Function
exitsub:
MsgBox Err.Description
End Function
Alert!! Code is untested!!