grahamjlaws
New member
- Local time
- Today, 06:48
- Joined
- Dec 18, 2006
- Messages
- 8
Hi, how can i best optimize this code for speed?
Private Sub cmdBOM_Click()
Dim blnOK As Boolean
If Me.LMsuccess = "No" Then
MsgBox "Please Import LM data before processing", vbInformation, "Processing BOMs"
Else
MsgBox ("Files Found")
'in Tools | References, make sure the ADO ' "Microsoft ActiveX Data Objects 2.1 Library" is checked
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim strPCode As String
Dim lngRecNo As Long
Dim lngRecCount As Long
Call acbInitMeter("BOM Manipulation", True)
lngRecCount = DCount("*", "tbom")
strSQL = "Select * From tbom"
Set rst = New ADODB.Recordset
rst.Open strSQL, CurrentProject.Connection, adOpenKeyset, _
adLockOptimistic, adCmdText
If Not rst.BOF And Not rst.EOF Then
'Initialize variables
strPCode = rst.Fields("pCode").Value
rst.MoveNext
Else
MsgBox "There are NO records in the recordset!", _
vbCritical, "No records Found!"
rst.Close
Set rst = Nothing
Exit Sub
End If
lngRecNo = 0
Do While Not rst.EOF
DoEvents
blnOK = acbUpdateMeter((lngRecNo / lngRecCount) * 100)
If Not blnOK Then
With Me
.BPsuccess = "No"
.BPdate = ""
End With
Call acbCloseMeter
rst.Close
Set rst = Nothing
'MsgBox "Operation Cancelled!", vbOKOnly + vbCritical, "Process BOMs"
Exit Sub
End If
If rst.Fields("pCode").Value = "." Then
rst.Fields("pCode").Value = strPCode
rst.Update
Else
strPCode = rst.Fields("pCode").Value
End If
'Move to the next record
lngRecNo = lngRecNo + 1
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Call acbCloseMeter
DoCmd.SetWarnings False
DoCmd.RunSQL "SELECT pCode, Bqty, bUnit " & _
"INTO tBuildUnit " & _
"FROM tBom " & _
"WHERE (((tBom.cCode) Is Null));"
DoCmd.SetWarnings True
MsgBox ("BOM processing completed successfully")
With Me
.BPsuccess = "Yes"
.BPdate = Now()
End With
End If
End Sub
Thanks,
Graham
Private Sub cmdBOM_Click()
Dim blnOK As Boolean
If Me.LMsuccess = "No" Then
MsgBox "Please Import LM data before processing", vbInformation, "Processing BOMs"
Else
MsgBox ("Files Found")
'in Tools | References, make sure the ADO ' "Microsoft ActiveX Data Objects 2.1 Library" is checked
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim strPCode As String
Dim lngRecNo As Long
Dim lngRecCount As Long
Call acbInitMeter("BOM Manipulation", True)
lngRecCount = DCount("*", "tbom")
strSQL = "Select * From tbom"
Set rst = New ADODB.Recordset
rst.Open strSQL, CurrentProject.Connection, adOpenKeyset, _
adLockOptimistic, adCmdText
If Not rst.BOF And Not rst.EOF Then
'Initialize variables
strPCode = rst.Fields("pCode").Value
rst.MoveNext
Else
MsgBox "There are NO records in the recordset!", _
vbCritical, "No records Found!"
rst.Close
Set rst = Nothing
Exit Sub
End If
lngRecNo = 0
Do While Not rst.EOF
DoEvents
blnOK = acbUpdateMeter((lngRecNo / lngRecCount) * 100)
If Not blnOK Then
With Me
.BPsuccess = "No"
.BPdate = ""
End With
Call acbCloseMeter
rst.Close
Set rst = Nothing
'MsgBox "Operation Cancelled!", vbOKOnly + vbCritical, "Process BOMs"
Exit Sub
End If
If rst.Fields("pCode").Value = "." Then
rst.Fields("pCode").Value = strPCode
rst.Update
Else
strPCode = rst.Fields("pCode").Value
End If
'Move to the next record
lngRecNo = lngRecNo + 1
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Call acbCloseMeter
DoCmd.SetWarnings False
DoCmd.RunSQL "SELECT pCode, Bqty, bUnit " & _
"INTO tBuildUnit " & _
"FROM tBom " & _
"WHERE (((tBom.cCode) Is Null));"
DoCmd.SetWarnings True
MsgBox ("BOM processing completed successfully")
With Me
.BPsuccess = "Yes"
.BPdate = Now()
End With
End If
End Sub
Thanks,
Graham