Dear friends,
I'm not so familiar with vba and i need your help. I want to adjust the following code in order to "copy" records which the "Type of Meal" = 3 only and not at all
Anybody can help?
Private Sub cmdCopy_Click()
On Error GoTo Err_cmdCopy_Click
Dim dbs As DAO.Database
Dim i As Integer
If Not Me.NewRecord Then
If DCount("Autonumber", "tblDietDetails", "[DayCode]=1 and [DietCode]=" & Forms!frmDietPlan.DietID) > 0 Then
Set dbs = CurrentDb
Me.Dirty = False
' DoCmd.RunCommand acCmdSave
For i = 2 To 7
dbs.Execute "INSERT INTO tblDietDetails ([pQty],[pSize],[pObject],[Type of Meal], [Food], [Qty], [Dosage], [Measure Unit], [MealCode])" & " SELECT [pQty],[pSize],[pObject],[Type of Meal], [Food], [Qty], [Dosage], [Measure Unit], [MealCode] FROM tblDietDetails WHERE [DietCode] = " & Forms!frmDietPlan.DietID & " and (DayCode=1 and TransferFromMonday=0)"
dbs.Execute "UPDATE tblDietDetails Set DietCode=" & Forms!frmDietPlan.DietID & " WHERE DietCode Is Null"
dbs.Execute "UPDATE tblDietDetails Set DayCode=" & i & " WHERE DayCode Is Null"
Next
dbs.Execute "UPDATE tblDietDetails Set TransferFromMonday=-1" & " Where [DietCode] = " & Forms!frmDietPlan.DietID & " and (DayCode=1 and TransferFromMonday=0)"
Me.Form.Requery
Set dbs = Nothing
Forms!frmDietPlan.cboGoToDiet = Null
cmdSave_Click
Forms!frmDietPlan.unbBreakfast.Requery
Forms!frmDietPlan.unbMeal2.Requery
Forms!frmDietPlan.unbMeal3.Requery
Forms!frmDietPlan.unbMeal4.Requery
Forms!frmDietPlan.unbMeal5.Requery
Forms!frmDietPlan.unbMeal6.Requery
Forms!frmDietPlan.unbMeal7.Requery
Else
MsgBox "Το πρόγραμμα της Δευτέρας είναι κενό. Συμπληρώστε το.", vbExclamation, "ΠΡΟΣΟΧΗ"
End If
End If
Exit_cmdCopy_Click:
Exit Sub
Err_cmdCopy_Click:
MsgBox Err.Description
Resume Exit_cmdCopy_Click
End Sub