Results 1 to 4 of 4
  1. #1
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167

    Problem with code.

    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

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    You can add to the WHERE clause:

    Forms!frmDietPlan.DietID & " and (DayCode=1 and TransferFromMonday=0 AND [Type of Meal] = 3)"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    thanks a lot. i will try and i will let you know.

    Thanks again

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    No problem!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Code problem
    By sboelitz in forum Programming
    Replies: 1
    Last Post: 06-15-2012, 08:35 AM
  2. Problem in report and used code...
    By manos39 in forum Reports
    Replies: 12
    Last Post: 11-23-2011, 05:24 PM
  3. Problem with Code
    By jackiea in forum Programming
    Replies: 1
    Last Post: 10-07-2011, 05:59 PM
  4. Code Problem
    By Jeddell in forum Programming
    Replies: 2
    Last Post: 09-29-2011, 06:31 PM
  5. Problem with Code
    By cujee75 in forum Programming
    Replies: 0
    Last Post: 03-10-2006, 02:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums