Results 1 to 7 of 7
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    Please Help Me Fix The Code

    The Following Code Is Working Perfectly with number fields.

    Please note "LoginIDNo" is Number Field, where as I want to change this to Text Field, e.g David instead of 2 (this is login id of david)
    The Text Field I want to use is [EntryPLogin By] How and what changes are required to do this. Help is needed.



    Private Sub cmdOpenReportDataop_Click()
    On Error GoTo Err_Handler

    Const REPORTNAME = "General Purchase wo Varification"
    Const MESSAGETEXT = _
    "A customer and both a start and end date must be selected."
    Dim strCriteria As String
    Dim strDateFrom As String, strDateTo As String

    ' make sure a customer and both dates are selected


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

    ' open report filtered to selected customer and date range
    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

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Filter parameters for text fields need apostrophe delimiters.

    "[EntryPLogin By]='" & Me.tbxLogin & "'"

    Date fields use the # character as delimiter.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    Please note the name of table: Purchases & Query: Pchase (I am mentioning this is required by you)

    I tried the following by replacing
    strCriteria = "LoginIDNo = " & Me.CboDataOp & _

    with

    strCriteria = "[EntryPLogin By]='" & Me.tbxLogin & "'"


    its giving me errors.







    Private Sub cmdOpenReportDataop_Click()

    On Error GoTo Err_Handler
    Const REPORTNAME = "General Purchase wo Varification"
    Const MESSAGETEXT = _
    "A customer and both a start and end date must be selected."
    Dim strCriteria As String
    Dim strDateFrom As String, strDateTo As String
    ' make sure a customer and both dates are selected
    If Not IsNull(Me.CboDataOp) And Not IsNull(Me.cboDateFrom) _
    And Not IsNull(Me.cboDateTo) Then
    strDateFrom = "#" & Format(Me.cboDateFrom, "yyyy-mm-dd") & "#"
    strDateTo = "#" & Format(DateAdd("d", 1, Me.cboDateTo), "yyyy-mm-dd") & "#"
    ' build string expression to filter report
    ' to selected customer and data range
    strCriteria = "[EntryPLogin By]='" & Me.tbxLogin & "'"
    " And PurDate >= " & strDateFrom & " And PurDate < " & strDateTo
    ' open report filtered to selected customer and date range
    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

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You are missing a "&" and the continuation character at the end of the line. Change it to:

    strCriteria = "[EntryPLogin By]='" & Me.tbxLogin & "'" & _

    John

  5. #5
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    its not working

    what is tbxlogin means??

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Where on your form is the Login Name that you want to use? Is it a column of the combo box Me.CboDataOp ?

    You want to refer to that instead of using Me.tbxLogin .

  7. #7
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    finally I figured it out.

    thanks June & John_G for your help



    I am using the following code, please check if you think there are any errors in code. Although its working fine.


    Private Sub cmdOpenReportDataop_Click()
    On Error GoTo Err_Handler

    Const REPORTNAME = "General Purchase wo Varification"
    Const MESSAGETEXT = _
    "A customer and both a start and end date must be selected."
    Dim strCriteria As String
    Dim strDateFrom As String, strDateTo As String

    ' make sure a customer and both dates are selected
    If Not IsNull(Me.CboDataOp) And Not IsNull(Me.cboDateFrom) _
    And Not IsNull(Me.cboDateTo) Then
    strDateFrom = "#" & Format(Me.cboDateFrom, "yyyy-mm-dd") & "#"
    strDateTo = "#" & Format(DateAdd("d", 1, Me.cboDateTo), "yyyy-mm-dd") & "#"
    ' build string expression to filter report
    ' to selected customer and data range

    strCriteria = "[EntryPLogin By]='" & Me.CboDataOp & "'" & _
    " And PurDate >= " & strDateFrom & " And PurDate < " & strDateTo

    ' open report filtered to selected customer and date range
    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

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

Similar Threads

  1. Replies: 4
    Last Post: 03-10-2014, 12:18 PM
  2. Report Code is not allowing return to main code
    By rcwiley in forum Programming
    Replies: 2
    Last Post: 06-16-2013, 10:31 AM
  3. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  4. Replies: 1
    Last Post: 05-04-2013, 12:19 PM
  5. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 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