Хотелось бы получить общий обзор кода на следующий код. Этот код является частью автоматизированного процесса принятия решений, чтобы определить, какие из них необходимо добавить в таблицу в базе данных. Я хотел бы иметь еще пару глаз, чтобы проверить ошибки синтаксиса и общие недостатки логики.Код доступа для доступа к VBA
Private Sub btnAddEnt_Click()
Dim strEnt As String
Dim Direct As Integer
Dim Indirect As Integer
Dim DirectNum As Currency
Dim IndirectNum As Currency
Dim db As Database
Set db = CurrentDb
Dim disRs As DAO.Recordset
Dim dayRs As DAO.Recordset
Dim Jan As Currency
Dim Feb As Currency
Dim Mar As Currency
Dim Apr As Currency
Dim May As Currency
Dim Jun As Currency
Dim Jul As Currency
Dim Aug As Currency
Dim Sep As Currency
Dim Oct As Currency
Dim Nov As Currency
Dim Dec As Currency
Dim DKClient As String
Dim DKNum As Integer
strEnt = "INSERT INTO EntList (EntityID, BusinessUnit, EntityName, Position, Location, Client, Dept, DistKey, Salary, Currency, SQ&A, BillRate, Util%, MeritDate, MeritRate) " & _
"VALUES ('" & Me.EntityID & "', '" & Me.BusinessUnit & "', '" & Me.EntityName & "', '" & Me.Position & "', '" & Me.Location & "', '" & Me.Client & "', '" & Me.Dept & "', '" & Me.DistKey & "', '" & Me.Salary & "', '" & Me.Currency & "', '" & Me.SG_A & "', '" & Me.BillRate & "', '" & Me.Util_ & "', '" & Me.MeritDate & "', '" & Me.Merit_ & "');"
DoCmd.RunSQL strEnt
Direct = (1 - Me.SG_A)
Indirect = Me.SG_A
If Direct > 0 Then
DirectNum = Direct * Me.Salary/12
End If
If Indirect > 0 Then
IndirectNum = Indirect * Me.Salary/12
End If
If Me.BillRate > 0 Then
Set dayRs = db.OpenRecordset("SELECT WrkDays FROM WrkDays ORDER BY WrkMonth;")
dayRs.MoveFirst
Set DayNum = dayRs.Fields("WrkDays")
While Not dayRs.EOF
Jan = (Me.BillRate * DayNum) * Me.Util_
dayRs.MoveNext
Feb = (Me.BillRate * DayNum) * Me.Util_
dayRs.MoveNext
Mar = (Me.BillRate * DayNum) * Me.Util_
dayRs.MoveNext
Apr = (Me.BillRate * DayNum) * Me.Util_
dayRs.MoveNext
May = (Me.BillRate * DayNum) * Me.Util_
dayRs.MoveNext
Jun = (Me.BillRate * DayNum) * Me.Util_
dayRs.MoveNext
Jul = (Me.BillRate * DayNum) * Me.Util_
dayRs.MoveNext
Aug = (Me.BillRate * DayNum) * Me.Util_
dayRs.MoveNext
Sep = (Me.BillRate * DayNum) * Me.Util_
dayRs.MoveNext
Oct = (Me.BillRate * DayNum) * Me.Util_
dayRs.MoveNext
Nov = (Me.BillRate * DayNum) * Me.Util_
dayRs.MoveNext
Dec = (Me.BillRate * DayNum) * Me.Util_
Wend
End If
If Me.DistKey <> "N/A" Then
Set disRs = db.OpenRecordset("SELECT Client, DistPer FROM DistMap WHERE DistKey = '" & Me.DistKey & "';")
disRs.MoveFirst
Set DKClient = disRs.Fields("Client")
Set DKNum = disRs.Fields("DistPer")
While Not disRs.EOF
If Direct > 0 Then
DoCmd.RunSQL ("INSERT INTO ForcastTrans (Location, Client, Department, Account, EntityID, Description, Currency, Month1, Month2, Month3, Month4, Month5, Month6, Month7, Month8, Month9, Month10, Month11, Month12) " & _
"VALUES ('" & Me.Location & "', DKClient, '" & Me.Dept & "', '5010 SALARIES/WAGES - ADMIN', '" & Me.EntityID & "', 'Payroll', '" & Me.Currency & "', DirectNum * DKNum, DirectNum * DKNum, DirectNum * DKNum, DirectNum * DKNum, DirectNum * DKNum, DirectNum * DKNum, DirectNum * DKNum, DirectNum * DKNum, DirectNum * DKNum, DirectNum * DKNum, DirectNum * DKNum, DirectNum * DKNum);")
End If
If Indirect > 0 Then
DoCmd.RunSQL ("INSERT INTO ForcastTrans (Location, Client, Department, Account, EntityID, Description, Currency, Month1, Month2, Month3, Month4, Month5, Month6, Month7, Month8, Month9, Month10, Month11, Month12) " & _
"VALUES ('" & Me.Location & "', DKClient, '" & Me.Dept & "', '7010 SALARIES/WAGES - ADMIN', '" & Me.EntityID & "', 'Payroll', '" & Me.Currency & "', IndirectNum*DKNum, IndirectNum * DKNum, IndirectNum * DKNum, IndirectNum * DKNum, IndirectNum * DKNum, IndirectNum * DKNum, IndirectNum * DKNum, IndirectNum * DKNum, IndirectNum * DKNum, IndirectNum * DKNum, IndirectNum * DKNum, IndirectNum * DKNum);")
End If
If Me.BillRate > 0 Then
DoCmd.RunSQL ("INSERT INTO ForcastTrans (Location, Client, Department, Account, EntityID, Description, Currency, Month1, Month2, Month3, Month4, Month5, Month6, Month7, Month8, Month9, Month10, Month11, Month12) " & _
"VALUES ('" & Me.Location & "', DKClient, '" & Me.Dept & "', '4900 CONSULTING FEES', '" & Me.EntityID & "', 'Revenue', '" & Me.Currency & "', Jan * DKNum, Feb * DKNum, Mar * DKNum, Apr * DKNum, May * DKNum, Jun * DKNum, Jul * DKNum, Aug * DKNum, Sep * DKNum, Oct * DKNum, Nov * DKNum, Dec * DKNum);")
End If
disRs.MoveNext
Wend
Else
If Direct > 0 Then
DoCmd.RunSQL ("INSERT INTO ForcastTrans (Location, Client, Department, Account, EntityID, Description, Currency, Month1, Month2, Month3, Month4, Month5, Month6, Month7, Month8, Month9, Month10, Month11, Month12) " & _
"VALUES ('" & Me.Location & "', '" & Me.Client & "', '" & Me.Dept & "', '5010 SALARIES/WAGES - ADMIN', '" & Me.EntityID & "', 'Payroll', '" & Me.Currency & "', DirectNum, DirectNum, DirectNum, DirectNum, DirectNum, DirectNum, DirectNum, DirectNum, DirectNum, DirectNum, DirectNum, DirectNum);")
End If
If Indirect > 0 Then
DoCmd.RunSQL ("INSERT INTO ForcastTrans (Location, Client, Department, Account, EntityID, Description, Currency, Month1, Month2, Month3, Month4, Month5, Month6, Month7, Month8, Month9, Month10, Month11, Month12) " & _
"VALUES ('" & Me.Location & "', '" & Me.Client & "', '" & Me.Dept & "', '7010 SALARIES/WAGES - ADMIN', '" & Me.EntityID & "', 'Payroll', '" & Me.Currency & "', IndirectNum, IndirectNum, IndirectNum, IndirectNum, IndirectNum, IndirectNum, IndirectNum, IndirectNum, IndirectNum, IndirectNum, IndirectNum, IndirectNum);")
End If
If Me.BillRate > 0 Then
DoCmd.RunSQL ("INSERT INTO ForcastTrans (Location, Client, Department, Account, EntityID, Description, Currency, Month1, Month2, Month3, Month4, Month5, Month6, Month7, Month8, Month9, Month10, Month11, Month12) " & _
"VALUES ('" & Me.Location & "', '" & Me.Client & "', '" & Me.Dept & "', '4900 CONSULTING FEES', '" & Me.EntityID & "', 'Revenue', '" & Me.Currency & "', Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);")
End If
End If
End Sub
Я получаю сообщение об ошибке на следующей строке кода Set DKClient = disRs.Fields ("Клиент") это говорит требуется Compile Object Error Но у меня есть объект уже объявлен ,
StackOverflow в действительности не предназначен для «общих обзоров коды». Есть ли определенная часть вашего кода, о которой вы особенно беспокоитесь? – mwolfe02
Я вижу, что этот вопрос имеет одно близкое голосование. Возможно, вы захотите попробовать [Code Review] (http://codereview.stackexchange.com/). – HansUp
Я обновил нижнюю часть вопроса относительно вопроса, который у меня есть. Извините, что –