Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    2 Star Lounger
    Join Date
    Apr 2004
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Date.... (vb/vba)

    If i want to check a field (txtFconfirm) on form FRMSHIP for the words "NOT SHIPPED" and also the field (txtFshipdate) to ensure if it's the current month otherwise Msgbox "ERROR" VBExclamation. How would I do this. I'm not sure how exactly to check for the current month.

    The date field is set as 12/16/2005

    any assistance would be helpful and appreciated as always.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Date.... (vb/vba)

    If InStr(UCase(txtFconfirm), "NOT SHIPPED") = 0 Then
    ' insert code to be executed if txtFconfirm does not contain "NOT SHIPPED"
    Else
    ' insert code to be executed if txtFconfirm contains "NOT SHIPPED"
    End If

    If Year(txtFShipdate) = Year(Date) And Month(txtFShipdate) = Month(Date) Then
    ' insert code to be executed if txtFShipdate is in the current month
    Else
    ' insert code to be executed if txtFShipdate is not in the current month
    End If

  3. #3
    2 Star Lounger
    Join Date
    Apr 2004
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date.... (vb/vba)

    Hans....

    Hello again my friend, how was you holiday's, I hope they were festive and enjoyable.

    If the TXTFCONFIRM field reads NOT SHIPPED, how would I go about disabling the F5 key. It's what the user presses to change the status from not shipped to shipped. The form that pops up is call frmDialog and when they hit the BTNOK it sends it. How would I disable this from happening what I want is to enure that the shipped product (If I ever have any) gets shipped in the current month.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Date.... (vb/vba)

    If you set the KeyPreview property of the form to True, you can trap all keystrokes at the form level.

    Private Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF5 Then
    If ... (conditions depending on text boxes) Then
    KeyCode = 0 ' no further processing of keystroke
    End If
    End If
    End Sub

  5. #5
    2 Star Lounger
    Join Date
    Apr 2004
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date.... (vb/vba)

    So what your saying is:

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF5 Then
    If txtFconfirm = "NOT SHIPPED" And Month(txtFShipdate) <> Month(Date) Then
    KeyCode = 0 ' no further processing of keystroke
    End If
    End If
    End Sub

    is that correct?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Date.... (vb/vba)

    Yes, if you want to check the entire contents of txtFconfirm, and only the month of txtFshipdate.

  7. #7
    2 Star Lounger
    Join Date
    Apr 2004
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date.... (vb/vba)

    Am I missing something her Hans because when I click on either the ICON, or the F5 key it still process's the shipment.

  8. #8
    2 Star Lounger
    Join Date
    Apr 2004
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date.... (vb/vba)

    hans, what if it's an ICON on the toolbar an I disable that?

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Date.... (vb/vba)

    Do the F5 key and the toolbar icon call the same procedure? If so, it's best to perform the test in this procedure, and get out if necessary:

    If txtFconfirm = "NOT SHIPPED" And Month(txtFShipdate) <> Month(Date) The
    Exit Sub
    End If

  10. #10
    2 Star Lounger
    Join Date
    Apr 2004
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date.... (vb/vba)

    Hans,

    Is there a way that I can check through VB what the system thinks the date is? It seems as if my code isnt even being read for the dates. so I think I best check it.

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Date.... (vb/vba)

    The Date function returns the current date. You could display thecurrent date in a message box:

    MsgBox Date

    or put a label on a form and set its caption to the current date:

    LabelName.Caption = Date

    where LabelName is the name of the label.

  12. #12
    2 Star Lounger
    Join Date
    Apr 2004
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date.... (vb/vba)

    ok, I was correct the system date and my date are somewhat different. The system thinks the date is 1/10/2006 and my date is 01/10/2006. what can I do to change the system date into thinking that it's actually 01/10/2006?

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Date.... (vb/vba)

    That looks like merely a difference in formatting. What is the result of

    MsgBox Month(txtFShipdate)

    and of

    Month(Date)

  14. #14
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date.... (vb/vba)

    Does this do it for you:

    <code>
    MsgBox Format(Date, "mm/dd/yyyy")
    </code>
    Legare Coleman

  15. #15
    2 Star Lounger
    Join Date
    Apr 2004
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date.... (vb/vba)

    MsgBox Month(txtFShipdate) = 12

    the other is 1

    so now how can I get it to look back 1 month for current date? the current shipdate would be in december then not in january.

    in stead of using current date, what about VBdate would that give me the 01 instead of just 1

Page 1 of 2 12 LastLast

Posting Permissions

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