Last post was too complicated. Simply...I'm using this VBA code to compute an oval measurement on a thumb. The first time the routine is called...it erases the thumb hole (Hole1) which draws it's data from a combo box where column #1 is a fraction value (7/8) and column #2 is the decimal (.875) and causes a null error. The 2nd time a value is entered the value remains and it finishes the routine. What I am trying to figure out is why the value is deleted only upon the initial entry? I also have a button which calls this routine. Everytime the button is used it causes a null error. Am I missing a statement to put the data into the Hole1 & Hole1F fields and if so...why on 2nd pass does it retain the values? Any idea's?
Private Sub OvalCalc()
Me.Hole1.Value = Me.Combo151.Column(2)
Me.Hole1F.Value = Me.Combo151.Column(1)
Dim db As Database
Dim rs As Recordset
Dim cutcount As Integer
Dim Cut As Integer
Dim CutnameH As String
Dim CutnameV As String
Set db = CurrentDb
Set rs = db.OpenRecordset("select * FROM MeasureT Where MeasureID=" & Me.MeasureID)
If OvalDegree <> 0 Then
'Calculate Oval Sin/Cos
Refresh
rs.Edit
rs.Fields("OvalVert") = Hole1
rs.Update
rs.Edit
rs.Fields("OvalDiff") = Round(OvalHoriz - OvalVert, 3)
rs.Update
rs.Edit
rs.Fields("OvalSin") = Round([OvalDiff] * Sin([OvalDegree] * 1.74532925199433E-02), 3)
rs.Fields("OvalCos") = Round([OvalDiff] * Cos([OvalDegree] * 1.74532925199433E-02), 3)
rs.Update
If OvalSin > OvalCos Then
rs.Edit
rs.Fields("OvalCuts") = Round(OvalSin / 0.036, 3)
Else
rs.Edit
rs.Fields("OvalCuts") = Round(OvalCos / 0.036, 3)
End If
rs.Update
Refresh
'Calculate # of Cuts
cutcount = Int(OvalCuts) + 1
Cut = 1
'Calculate Oval Starting point
If ThumbSlugType = "VIT: Vise IT" Then
rs.Edit
rs.Fields("OvalHX") = 0
rs.Fields("OvalVx") = 0
Else
rs.Edit
rs.Fields("OvalVx") = Hole1FR
rs.Fields("OvalHx") = Hole1LR
End If
rs.Update
Refresh
'Calculate Oval cuts
Do While Cut < 10
CutnameH = "OvalH" + Right(Str(Cut), 1)
CutnameV = "OvalV" + Right(Str(Cut), 1)
rs.Edit
If Cut > cutcount Then
rs.Fields(CutnameV) = 0
rs.Fields(CutnameH) = 0
Else
rs.Fields(CutnameV) = OvalVx - Round((OvalSin / cutcount) * Cut, 3)
If rs.Fields("LeftHand") = -1 Then
rs.Fields(CutnameH) = OvalHx - Round((OvalCos / cutcount) * Cut, 3)
Else
rs.Fields(CutnameH) = OvalHx + Round((OvalCos / cutcount) * Cut, 3)
End If
End If
rs.Update
Cut = Cut + 1
Loop
Refresh
rs.Close
End If
Set rs = Nothing
db.Close
End Sub
I have linked a copy of the database file ([FONT="]https://drive.google.com/file/d/0Bxe4EISu1gzEd1JEQnZlN2REQjA/view?usp=sharing ) It is too large to upload to the website directly.
[/FONT]
Private Sub OvalCalc()
Me.Hole1.Value = Me.Combo151.Column(2)
Me.Hole1F.Value = Me.Combo151.Column(1)
Dim db As Database
Dim rs As Recordset
Dim cutcount As Integer
Dim Cut As Integer
Dim CutnameH As String
Dim CutnameV As String
Set db = CurrentDb
Set rs = db.OpenRecordset("select * FROM MeasureT Where MeasureID=" & Me.MeasureID)
If OvalDegree <> 0 Then
'Calculate Oval Sin/Cos
Refresh
rs.Edit
rs.Fields("OvalVert") = Hole1
rs.Update
rs.Edit
rs.Fields("OvalDiff") = Round(OvalHoriz - OvalVert, 3)
rs.Update
rs.Edit
rs.Fields("OvalSin") = Round([OvalDiff] * Sin([OvalDegree] * 1.74532925199433E-02), 3)
rs.Fields("OvalCos") = Round([OvalDiff] * Cos([OvalDegree] * 1.74532925199433E-02), 3)
rs.Update
If OvalSin > OvalCos Then
rs.Edit
rs.Fields("OvalCuts") = Round(OvalSin / 0.036, 3)
Else
rs.Edit
rs.Fields("OvalCuts") = Round(OvalCos / 0.036, 3)
End If
rs.Update
Refresh
'Calculate # of Cuts
cutcount = Int(OvalCuts) + 1
Cut = 1
'Calculate Oval Starting point
If ThumbSlugType = "VIT: Vise IT" Then
rs.Edit
rs.Fields("OvalHX") = 0
rs.Fields("OvalVx") = 0
Else
rs.Edit
rs.Fields("OvalVx") = Hole1FR
rs.Fields("OvalHx") = Hole1LR
End If
rs.Update
Refresh
'Calculate Oval cuts
Do While Cut < 10
CutnameH = "OvalH" + Right(Str(Cut), 1)
CutnameV = "OvalV" + Right(Str(Cut), 1)
rs.Edit
If Cut > cutcount Then
rs.Fields(CutnameV) = 0
rs.Fields(CutnameH) = 0
Else
rs.Fields(CutnameV) = OvalVx - Round((OvalSin / cutcount) * Cut, 3)
If rs.Fields("LeftHand") = -1 Then
rs.Fields(CutnameH) = OvalHx - Round((OvalCos / cutcount) * Cut, 3)
Else
rs.Fields(CutnameH) = OvalHx + Round((OvalCos / cutcount) * Cut, 3)
End If
End If
rs.Update
Cut = Cut + 1
Loop
Refresh
rs.Close
End If
Set rs = Nothing
db.Close
End Sub
I have linked a copy of the database file ([FONT="]https://drive.google.com/file/d/0Bxe4EISu1gzEd1JEQnZlN2REQjA/view?usp=sharing ) It is too large to upload to the website directly.
[/FONT]
Last edited: