Results 1 to 18 of 18

Thread: msgbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    11

    msgbox

    Hi i have a database with a form that i have added a checkbox to (check325), what i want to do is have a msgbox appear if command 261 is clicked to say 'please complete check box'. here is the original code.
    vb Code:
    1. Private Sub Command261_Click()
    2. 'On Error GoTo Err_Command261_Click
    3.     If IsNull(Me.Text266) Or Trim(Me.Text266) = "" Then
    4.     MsgBox "Please provide Work Status", vbInformation, "Cworks"
    5.     Me.Text266.SetFocus
    6.     Exit Sub
    7.     End If
    8.  
    9.   Dim rspmsched As DAO.Recordset
    10.   Dim response
    11.  
    12.     If Me.WorkStatus.Column(0) = 2 Then
    13.     If IsNull(Me.ActDateStart) Or IsNull(Me.ActDateEnd) Then
    14.         MsgBox "Please provide an Actual Start Date and  Actual End Date", vbOKOnly + vbExclamation
    15.         Me.ActDateStart.SetFocus
    16.     Else
    17.         response = MsgBox("Closed work orders cannot be modified. Do you want to proceeed ?", vbYesNo + vbInformation + vbDefaultButton2, "Confirm Save")
    18.         If response = vbYes Then
    19.            If Me.WorkType = 2 And Me.WorkStatus = 2 Then
    20.                
    21.                Set rspmsched = CurrentDb.OpenRecordset("Select * from [PM Schedule] where [PM Schedule].PMNo='" & Replace(Me.PMNo, "'", "''") & "' and [PM Schedule].TypePMgen='2'")
    22.                     If rspmsched.EOF = False Then
    23.                             rspmsched.Edit
    24.                             rspmsched![ActualCompDate] = Format(Me.ActDateEnd, "Short Date")
    25.                             rspmsched![nextdate] = rspmsched![ActualCompDate] + (rspmsched![Frequency] * rspmsched![FreqUnits])
    26.                             rspmsched.Update
    27.                     End If
    28.                     rspmsched.Close
    29.             End If
    30.             DoCmd.Close
    31.         Else
    32.             Exit Sub
    33.         End If
    34.     End If
    35.   ElseIf Me.WorkStatus.Column(0) <> 2 Then
    36.     DoCmd.Close
    37.   End If
    38.  
    39. End Sub

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: msgbox

    Welcome to the forums.

    I guess what you are saying is that what you have doesn't work, so try this
    Code:
    If Text266.Text = vbNullString Then
    Also, give your controls meaningful names. It makes it a little easier to figure out what does what when you use things like txtWorkStatus or cmdCheckStatus as opposed to Text266 and Command261

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: msgbox

    Hi thanks for the response, the original code does work but what i want to do is add in some code so that if the new checkbox that i have added is not checked a message box appears to say 'please complete checklist'.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: msgbox

    Oh, ok. Then do something like
    Code:
    If Check1.Value = vbUnchecked Then
         Msgbox "Please Complete The CheckList"
         Exit Sub
    End If

  5. #5
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    Re: msgbox

    Hi Clarke,

    One other comment, too.

    The test "IsNull(Me.Text266)" is always going to return false if this is referring to a textbox on your form. VB never sets the default property (which is Text) for a textbox to Null. That's only necessary if the item you're testing for Null is coming from a database - I.E. testing a recordset column. So you can just do the one test on Trim(Me.Text266) = ""

    BTW ... suggest that you indent your code - it will be easier to read. (That section wasn't indented as far as I could see).

    - Max
    The name's "Peck" .... "Max Peck"

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: msgbox

    Good point Max Peck.

    It should be
    Code:
    If Text266.Text = vbNullString

  7. #7
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    Re: msgbox

    Hi Hack!

    Quote Originally Posted by Hack
    Good point Max Peck.

    It should be
    Code:
    If Text266.Text = vbNullString
    Actually he needs to say:

    If Trim(Text266.Text) = vbNullString. Otherwise an imbedded blank will fail that test. vbNullString is not the same as a SQL NULL - it's simply ("").

    -Max
    The name's "Peck" .... "Max Peck"

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: msgbox

    thanks again, i entered the code before the line 'If Me.WorkStatus.Column(0) = 2 Then' but it didnt work when i clicked command 261 it just jump straight to the closed work orders cannot be modified msgbox. any hints would be appreciated.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: msgbox

    What is Me.WorkStatus.Column(0) and what does this have to do with your checkbox?

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: msgbox

    its in the original code, where should i insert the new code then?

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: msgbox

    Quote Originally Posted by clarke24
    its in the original code, where should i insert the new code then?
    Its not my program, so I'm not sure where it should go. Where would it, to you, make the most sense to do this check?

  12. #12

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: msgbox

    it needs to go in before it checks the actual dates are null. but when i enter it in it doesnt run properly

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: msgbox

    Post what you have for Command261_Click now, with that checkbox check added.

  14. #14

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: msgbox

    Code:
    Private Sub Command261_Click()
    'On Error GoTo Err_Command261_Click
        If IsNull(Me.Text266) Or Trim(Me.Text266) = "" Then
        MsgBox "Please provide Work Status", vbInformation, "Cworks"
        Me.Text266.SetFocus
        Exit Sub
        End If
    
      Dim rspmsched As DAO.Recordset
      Dim response
    If Check325.Value = False Then
         MsgBox "Please Complete The CheckList"
         Exit Sub
    End If
        If Me.WorkStatus.Column(0) = 2 Then
        If IsNull(Me.ActDateStart) Or IsNull(Me.ActDateEnd) Then
            MsgBox "Please provide an Actual Start Date and  Actual End Date", vbOKOnly + vbExclamation
            Me.ActDateStart.SetFocus
        Else
               response = MsgBox("Closed work orders cannot be modified. Do you want to proceeed ?", vbYesNo + vbInformation + vbDefaultButton2, "Confirm Save")
            If response = vbYes Then
               If Me.WorkType = 2 And Me.WorkStatus = 2 Then
                    
                   Set rspmsched = CurrentDb.OpenRecordset("Select * from [PM Schedule] where [PM Schedule].PMNo='" & Replace(Me.PMNo, "'", "''") & "' and [PM Schedule].TypePMgen='2'")
                        If rspmsched.EOF = False Then
                                rspmsched.Edit
                                rspmsched![ActualCompDate] = Format(Me.ActDateEnd, "Short Date")
                                rspmsched![nextdate] = rspmsched![ActualCompDate] + (rspmsched![Frequency] * rspmsched![FreqUnits])
                                rspmsched.Update
                        End If
                        End If
                        rspmsched.Close
                End If
             DoCmd.Close
            Else
                Exit Sub
            End If
        End If
      ElseIf Me.WorkStatus.Column(0) <> 2 Then
        DoCmd.Close
      End If
    
    End Sub
    Last edited by Hack; Oct 22nd, 2007 at 01:13 PM. Reason: Added Cpde Tags

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: msgbox

    I added [code]your code goes here[/code] tags to your post so it would be easier to read. If would be good if you could use them in the future. Thanks.
    Code:
    'Not
    If Command325.Value = False Then
    'but rather
    If Command325.Value = vbUnchecked Then

  16. #16

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: msgbox

    tried that but it comes up with variable not defined

  17. #17
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    Re: msgbox

    Quote Originally Posted by clarke24
    tried that but it comes up with variable not defined
    Command325 is undefined (not in your code anyway) ... I think Hack meant to say ...

    if Check325.value = vbUnChecked ...

    -Max
    The name's "Peck" .... "Max Peck"

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

  18. #18
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: msgbox

    Quote Originally Posted by clarke24
    tried that but it comes up with variable not defined
    On what line does the error occur?

Posting Permissions

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



Click Here to Expand Forum to Full Width