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

    VBA Help Requested

    Hi,

    i need help with the following vba code. I have no knowledge on VBA.


    Private Sub Command49_Click()
    On Error GoTo Err_Handler

    Const REPORTNAME = "Cheque Book Detail"
    Const MESSAGETEXT = "Both a Cheque Paid To and Account Catagory must be selected."
    Dim strCriteria As String

    ' build string expression to filter report
    ' to selected Cheque Paid To and Account Catagory
    strCriteria = "[ChqIssuedWorker] = """ & Me.issu2 & """"
    " And [ChqTypePmt] = """ & Me.AccountCatagory & """"

    ' make sure a Cheque Paid To is selected
    If Not IsNull(Me.issu2) And Not IsNull(Me.AccountCatagory) Then
    ' open report filtered to selected Cheque Paid To
    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



    The problem is in the following line
    " And [ChqTypePmt] = """ & Me.AccountCatagory & """"


    and I have no clue how to fix this.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Where did you get the code from?

    What is the problem - are you getting an error message, what is the message?
    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
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Try:

    strCriteria = "[ChqIssuedWorker] = """ & Me.issu2 & """"
    strCriteria = strCriteria & " And [ChqTypePmt] = """ & Me.AccountCatagory & """"

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Another way is to use the line continuation & _ at then end.

    strCriteria = "[ChqIssuedWorker] = """ & Me.issu2 & """" & _
    " And [ChqTypePmt] = """ & Me.AccountCatagory & """"

  5. #5
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    Thank you Ray Milhon
    Both of the following are working great, can you tell me what is different about them.


    strCriteria = "[ChqIssuedWorker] = """ & Me.issu2 & """"
    strCriteria = strCriteria & " And [ChqTypePmt] = """ & Me.AccountCatagory & """"

    And

    strCriteria = "[ChqIssuedWorker] = """ & Me.issu2 & """" & _
    " And [ChqTypePmt] = """ & Me.AccountCatagory & """"


    Thank you once again.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    The first syntax builds up the complete criteria string in steps by concatenation with the variable. Useful for debugging very long code lines.

    The second is really one long statement that is continued on multiple lines. The underscore (_) is VBA line continuation character. It means 'read the following line as continution of this line'. Just makes code easier to read without having to scroll horizontally to read a complete line.
    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.

  7. #7
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    June7 explains it very well.

  8. #8
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    thx June & Ray

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

Similar Threads

  1. Replies: 2
    Last Post: 10-01-2011, 02:00 PM
  2. Guidance on grouping students and staff requested
    By StudentTeacher in forum Forms
    Replies: 5
    Last Post: 07-22-2011, 07:50 AM
  3. Requested Password in new database access
    By baldo10 in forum Access
    Replies: 3
    Last Post: 09-07-2010, 04:23 AM
  4. Replies: 0
    Last Post: 03-16-2010, 08:10 PM
  5. Help requested for calculating age
    By techexpressinc in forum Queries
    Replies: 3
    Last Post: 01-28-2009, 11:29 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