Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    VBA Code help

    How to change the vba code

    I was using this code previously


    Me.cboFrom = VBA.Date

    Before I was using 2/20/2016



    What should be the new Code for

    Me.cboMonthFrom = VBA.Date

    Where the input value will be Month name e.g January, February, March, April etc

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Are you looking for this?

    Format(VBA.Date,"mmmm")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    theres probably several ways to do it but try this
    Code:
    Me.Text0 = MonthName(Month(Date))

  4. #4
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    Thanks pbaldy
    this is what i was looking for
    Format(VBA.Date,"mmmm")

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    Am trying to modifying the following but am totally lost.

    Private Sub cmdOpenReportSingle_Click()
    On Error GoTo Err_Handler

    Const REPORTNAME = "1A"
    Const MESSAGETEXT = "Both a start and end date must be selected."
    Dim strCriteria As String
    Dim strDateFrom As String, strDateTo As String

    ' make sure a customer is selected
    If Not IsNull(Me.cboDateFrom) And Not IsNull(Me.cboDateTo) Then
    strDateFrom = "#" & Format(Me.cboDateFrom, "yyyy-mm-dd") & "#"
    strDateTo = "#" & Format(DateAdd("d", 1, Me.cboDateTo), "mmmm") & "#"
    ' build string expression to filter report
    ' to selected data range
    strCriteria = "PurDate >= " & strDateFrom & " And PurDate < " & strDateTo

    ' open report filtered to selected customer
    DoCmd.OpenReport REPORTNAME, _
    View:=acViewPreview, _
    WhereCondition:=strCriteria
    Else
    MsgBox MESSAGETEXT, vbExclamation, "Invalid operation"
    End If

    Exit_Here:
    Exit Sub

    Err_Handler:
    MsgBox Err.Description, vbExclamation, "Error"
    Resume Exit_Here
    End Sub



    With the above code I input dates as 19/02/2014 it works (with the Db I am using not referring to this sample 01A).

    Now I made some changes in form where I use Start: Month as January With selecting Year 2014
    And End Month February 2016, I am not getting the result. I think there is an issue of format & need to add Year in the code.
    But I don't know how to do that.

    If someone can fix or help me fix the code I will be greatful.


    For better understanding I have attached Sample 01A. Please open the form DialogACDC

    Sample 01A.zip

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Well, your combos are only returning a month name, so your formulas don't actually evaluate to valid dates. You aren't using the year textboxes. It would be simpler to have the user enter two valid dates.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    how can I do that, can you guide me.

  9. #9
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    how can I do that, can you guide me.
    Basically the function of this report is to give detail by month not between dates & between specific period of year or years

  10. #10
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    I need Help

  11. #11
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    Sample 01A1.zip

    there's a thousand ways of doing what you are wanting but a few things were necessary. in your code your report name was missing part. added purchase date to your query so that it could have actual dates to pull from, you don't have to display it but it helps with the sort that you wanted. added two new combo boxes to show kind of what paul is asking. you have the actual dates, use them. you don't have to display them so the combo boxes only show the month and year but actually sort by the date.

  12. #12
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    vicsaccess Thank you for your kind help & specially how beautifully you have explained on the coding. It's helping me a lot understanding better.

    The report generated was showing all the descriptions so I added the following in the query 1AB to filter report by Company Title & Item Description to show the details.

    added Criteria [Forms]![DialogMonYr].[Cbodcpt] under PurCompanyName
    & added Criteria [Forms]![DialogMonYr].[Cboactit] under Purchase Description

    Now the Company Title Combo Box is Blank and the report is also blank.

    Please see the attached sample.


    Sample 01B.zip

  13. #13
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    I have fixed the problem with combo boxes now its giving me the Company Title & Item Description.
    But when I run the report its asking me to "ENTER PARAMETER VALUE" Pur Date

    Where as in combo box "cbostart" & "cboend" date range is already given, and report is blank.


    Please check this Sample. Sample 01C.zip

  14. #14
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Look at the query "1AB". Why is the "Show" check box unchecked for the column "PurDate"?

    Shouldn't begin object names with numbers. The Access Gnomes get testy and can cause all kinds of random errors.
    Also shouldn't use spaces, special characters or punctuation in object names.

    For combo box "Cboactit", why are you using a totals query? Better to use the keyword "distinct" (IMO).
    Code:
    SELECT DISTINCT Purchases.PurCompanyName
    FROM Purchases
    ORDER BY Purchases.PurCompanyName;
    You have a row source for the combo box "Cbodcpt", but then you change it in the afterupdate event of combo box "Cboactit"???

    Found an error in your logic for the date tests. If you leave the date combo boxes blank, the report still tries to open. Your custom error message does not get displayed.


    ----- Fixes ------
    I checked the "Show" check box for the column "PurDate". No more parameter request.
    I changed the row source for the combo box "Cbodcpt" and changed the afterupdate code for combo box "Cboactit".
    And I changed the date test when opening the report. (see the code)
    Attached Files Attached Files

  15. #15
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    Click image for larger version. 

Name:	1AB.jpg 
Views:	36 
Size:	167.8 KB 
ID:	23771 Click image for larger version. 

Name:	1ABrpt.jpg 
Views:	35 
Size:	239.9 KB 
ID:	23772

    I have done what you advised. I entered the following values and in report months are showing values instead of summing them up into a single sum value of month.
    Sample Sample 01C is attached.


    Sample 01C.zip
    Last edited by aamer; 02-21-2016 at 10:02 AM.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 20
    Last Post: 10-13-2015, 09:05 AM
  2. Replies: 3
    Last Post: 10-16-2014, 08:49 AM
  3. Replies: 4
    Last Post: 03-10-2014, 12:18 PM
  4. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  5. Replies: 1
    Last Post: 05-04-2013, 12:19 PM

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