Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2010
    Posts
    32

    Unanswered: buttons in forms

    I have two buttons in one of my forms, calculate which runs a sumUpdate() function and Save which saves the record.

    Is it possible to make the Save button hidden until the calculate button is pressed? This way it is not saved without calculating totals.

    If so how and where would I put this?

  2. #2
    Join Date
    Aug 2009
    Location
    Up Nort' Wi
    Posts
    140
    Form_Load()
    cmd_Save.Visible = False

    End Sub

    cmd_Calculate_Click

    {Do a bunch of stuff}
    If ConditionsAreMet Then
    cmd_Save.Visible = True
    Endif

    End Sub

    Sam, hth
    Good, fast, cheap...Pick 2.

  3. #3
    Join Date
    Sep 2010
    Posts
    32
    where would I put that in my current code

    Code:
    Option Compare Database
    
    Private Sub cmdDate_Click()
    InputDateField Date, "Select Date"
    End Sub
    
    Private Sub cmdBirthday_Click()
    
    End Sub
    Function sumUpdate2()
    
    WOAVG = IIf([WOIssued] = 0, 0, Val(Nz([WOCompleted], 0)) / Val(Nz([WOIssued], 0)))
    
    End Function
    Function sumUpdate3()
    
    PMSAVG = IIf([PMSIssued] = 0, 0, Val(Nz([PMSCompleted], 0)) / Val(Nz([PMSIssued], 0)))
    
    End Function
    Function sumUpdate4()
    
    PJTAVG = IIf([PJTIssued] = 0, 0, Val(Nz([PJTCompleted], 0)) / Val(Nz([PJTIssued], 0)))
    
    End Function
    
    
    Function sumUpdate()
    
    WOBacklog = Val(Nz(WOIssued, 0)) - Val(Nz(WOCompleted, 0))
    
    PMSBacklog = Val(Nz(PMSIssued, 0)) - Val(Nz(PMSCompleted, 0))
    
    TOTALPLANNED = Val(Nz(WOHours, 0)) + Val(Nz(PMSHours, 0)) + Val(Nz(SOCHours, 0)) + Val(Nz(PJTHours, 0))
    
    TOTALAVAIL = Val(Nz(TOTALPLANNED, 0)) + Val(Nz(DINHours, 0))
    
    If [WOAVG] = 0 And [PMSAVG] = 0 And [PJTAVG] = 0 Then
      TOTALPERCENT = 0
      
    ElseIf [WOAVG] <> 0 And [PMSAVG] = 0 And [PMSIssued] = 0 And [PJTAVG] = 0 And [PJTIssued] = 0 Then
      TOTALPERCENT = [WOAVG]
      
    ElseIf [PMSAVG] <> 0 And [WOAVG] = 0 And [WOIssued] = 0 And [PJTAVG] = 0 And [PJTIssued] = 0 Then
      TOTALPERCENT = [PMSAVG]
      
    ElseIf [PJTAVG] <> 0 And [WOAVG] = 0 And [WOIssued] = 0 And [PMSAVG] = 0 And [PMSIssued] = 0 Then
      TOTALPERCENT = [PJTAVG]
      
    ElseIf [WOAVG] <> 0 And [PMSAVG] = 0 And [PMSIssued] <> 0 And [PJTAVG] = 0 And [PJTIssued] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0)) + Val(Nz([PJTAVG], 0))) / 3)
      
    ElseIf [WOAVG] = 0 And [WOIssued] <> 0 And [PMSAVG] <> 0 And [PJTAVG] = 0 And [PJTIssued] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0)) + Val(Nz([PJTAVG], 0))) / 3)
      
    ElseIf [WOAVG] = 0 And [WOIssued] <> 0 And [PMSAVG] = 0 And [PMSIssued] <> 0 And [PJTAVG] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0)) + Val(Nz([PJTAVG], 0))) / 3)
      
    ElseIf [WOAVG] <> 0 And [PMSAVG] <> 0 And [PJTAVG] = 0 And [PJTIssued] = 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0))) / 2)
    
    ElseIf [WOAVG] <> 0 And [PMSAVG] <> 0 And [PJTAVG] = 0 And [PJTIssued] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0)) + Val(Nz([PJTAVG], 0))) / 3)
      
    ElseIf [WOAVG] <> 0 And [PMSAVG] = 0 And [PMSIssued] = 0 And [PJTAVG] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PJTAVG], 0))) / 2)
      
    ElseIf [WOAVG] <> 0 And [PMSAVG] = 0 And [PMSIssued] <> 0 And [PJTAVG] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0)) + Val(Nz([PJTAVG], 0))) / 3)
      
    ElseIf [WOAVG] = 0 And [WOIssued] = 0 And [PMSAVG] <> 0 And [PJTAVG] <> 0 Then
      TOTALPERCENT = ((Val(Nz([PMSAVG], 0)) + Val(Nz([PJTAVG], 0))) / 2)
    
    ElseIf [WOAVG] = 0 And [WOIssued] <> 0 And [PMSAVG] <> 0 And [PJTAVG] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0)) + Val(Nz([PJTAVG], 0))) / 3)
      
    ElseIf [WOAVG] <> 0 And [PMSAVG] = 0 And [PMSIssued] <> 0 And [PJTAVG] = 0 And [PJTIssued] = 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0))) / 2)
      
    ElseIf [WOAVG] = 0 And [WOIssued] <> 0 And [PMSAVG] <> 0 And [PJTAVG] = 0 And [PJTIssued] = 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0))) / 2)
      
    ElseIf [WOAVG] <> 0 And [PMSAVG] = 0 And [PMSIssued] = 0 And [PJTAVG] = 0 And [PJTIssued] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PJTAVG], 0))) / 2)
      
    ElseIf [WOAVG] = 0 And [WOIssued] = 0 And [PMSAVG] <> 0 And [PJTAVG] = 0 And [PJTIssued] <> 0 Then
      TOTALPERCENT = ((Val(Nz([PJTAVG], 0)) + Val(Nz([PMSAVG], 0))) / 2)
      
    ElseIf [WOAVG] = 0 And [WOIssued] <> 0 And [PMSAVG] = 0 And [PMSIssued] = 0 And [PJTAVG] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PJTAVG], 0))) / 2)
      
    ElseIf [WOAVG] = 0 And [WOIssued] = 0 And [PMSAVG] = 0 And [PMSIssued] <> 0 And [PJTAVG] <> 0 Then
      TOTALPERCENT = ((Val(Nz([PMSAVG], 0)) + Val(Nz([PJTAVG], 0))) / 2)
      
    ElseIf [WOAVG] <> 0 And [PMSAVG] = 0 And [PMSIssued] <> 0 And [PJTAVG] = 0 And [PJTIssued] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0)) + Val(Nz([PJTAVG], 0))) / 3)
      
    ElseIf [WOAVG] = 0 And [WOIssued] <> 0 And [PMSAVG] <> 0 And [PJTAVG] = 0 And [PJTIssued] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0)) + Val(Nz([PJTAVG], 0))) / 3)
      
    ElseIf [WOAVG] = 0 And [WOIssued] <> 0 And [PMSAVG] = 0 And [PMSIssued] <> 0 And [PJTAVG] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0)) + Val(Nz([PJTAVG], 0))) / 3)
      
    ElseIf [WOAVG] <> 0 And [PMSAVG] <> 0 And [PJTAVG] <> 0 Then
      TOTALPERCENT = ((Val(Nz([WOAVG], 0)) + Val(Nz([PMSAVG], 0)) + Val(Nz([PJTAVG], 0))) / 3)
      
    End If
    
    End Function
    
    
    Private Sub Command70_Click()
    On Error GoTo Err_Command70_Click
    
        Dim stAppName As String
    
        stAppName = "=sumUpdate()"
        Call Shell(stAppName, 1)
    
    Exit_Command70_Click:
        Exit Sub
    
    Err_Command70_Click:
        MsgBox Err.Description
        Resume Exit_Command70_Click
        
    End Sub
    
    Private Sub Detail_Click()
    
    End Sub
    
    Private Sub PJTAVG_BeforeUpdate(Cancel As Integer)
    
    End Sub
    
    Private Sub SOCHours_BeforeUpdate(Cancel As Integer)
    
    End Sub
    Private Sub SaveR_Click()
    On Error GoTo Err_SaveR_Click
    
    
        DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
        DoCmd.GoToRecord , , acNewRec
        
    Exit_SaveR_Click:
        Exit Sub
    
    Err_SaveR_Click:
        MsgBox Err.Description
        Resume Exit_SaveR_Click
        
    End Sub
    Private Sub Next_Click()
    On Error GoTo Err_Next_Click
    
    
        DoCmd.GoToRecord , , acNewRec
    
    Exit_Next_Click:
        Exit Sub
    
    Err_Next_Click:
        MsgBox Err.Description
        Resume Exit_Next_Click
        
    End Sub
    
    Private Sub TOTALAVAIL2_BeforeUpdate(Cancel As Integer)
    
    End Sub
    The bold section is what happens when calculate is pressed

  4. #4
    Join Date
    Sep 2006
    Posts
    265
    Alternatively, I use a Tick Box updated after Calculation is performed:

    Code:
            If .[Calc] <> True Then
                MsgBox "You need to perform a Recalcuation to obtain the correct price values", vbOKOnly
                Exit Function
            Else
                ....
           End If
    Simon

  5. #5
    Join Date
    Sep 2010
    Posts
    32
    This is calculating employee productivity through out the day depending on the type of jobs they have been assigned and completed.

  6. #6
    Join Date
    Sep 2010
    Posts
    32
    Any help on this, how would I fit that first reply into my code?

    Thanks

  7. #7
    Join Date
    Aug 2009
    Location
    Up Nort' Wi
    Posts
    140
    Sorry, been out of the office this week.

    Actually the two subs are defined in that code...Form_Load() and cmd_Calculate_Click() are the events.

    I'll use the Code block to step it out so it'll look more like this:

    Code:
    Form_Load()
    
         cmd_Save.Visible = False
    
    End Sub
    
    cmd_Calculate_Click
    
         {Your calculating/errorchecking/etc here}
    
         If ConditionsAreMet Then
              cmd_Save.Visible = True
         Endif
    
    End Sub

    Sam, hth
    Good, fast, cheap...Pick 2.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •