Results 1 to 13 of 13

Thread: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    8

    ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    Here is the total code.
    VB Code:
    1. Dim strGenre As String
    2.     Dim strPlatform As String
    3.     Dim strFilter As String
    4.     'if the value in this combo box is null, then show all records
    5.     If IsNull(Me.cboGenre.Value) Then
    6.         strGenre = "Like '*'"
    7.     Else
    8.         strGenre = "='" & Me.cboGenre.Value & "'"
    9.     End If
    10.      'if the value in this combo box is null, then show all records
    11.     If IsNull(Me.cboPlatform.Value) Then
    12.         strPlatform = "Like '*'"
    13.     Else
    14.         strPlatform = "='" & Me.cboPlatform.Value & "'"
    15.     End If
    16.     'combining criteria to form a WHERE clause
    17. strFilter = "[Genre] " & strGenre & " AND [Platform] " & strPlatform
    18.    
    19.     With Reports![rptTopRented]
    20.          .Filter = strFilter
    21.          .FilterOn = True
    22.     End With


    The bit I want to change to allow the numerical data is:

    VB Code:
    1. Else
    2.         strPlatform = "=' " & Me.cboPlatform.Value & " ' "
    3.     End If

    The combo box names 'cboPlatform' is a list of Number ID's. And since currently its interperated as text, I've been told to maybe adjust or take out the qualifiers (I dont know what a qualifier is) in that bit of code to cater for numerical data.

    Also, I have a code, where, I want select a field (which has numbers too) and simply show ONLY the HIGHLEST value. What do I need to add to this code in order to do this?

    VB Code:
    1. strFilter = "[Genre] " & strGenre & " AND [Platform] " & strPlatform

    help ASAP appreciated. Project due tommorro!

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    The qualifiers are the single quotation marks you have included in the generation of the strPlatform string. Quote marks are not needed when passing a numeric value in a filter. Changing your code to the following should work. I also converted the value of cboPlatform to the "Long" datatype.

    VB Code:
    1. Else
    2.         strPlatform = "=" & CLng(Me.cboPlatform.Value)
    3. End If
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    8

    Re: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    I get the error, 'Type Mismatch' when I try to run the filter under those changes you've advised.


    Is there a way to alter the code while keeping the value declared as string??

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    What is the datatype of the "Platform" field?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    8

    Re: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    The data type is a 'Number'. It refers to a report based on a query.

    Here is the code again, please refer to this verison (I made a small mistake in typo :P )

    VB Code:
    1. Private Sub cmdapplyfilter_Click()
    2.  
    3. 'declare variables in which the values from the combo boxes will be stored in
    4.     Dim strGenre As String
    5.     Dim strPlatform As Long
    6.     Dim strFilter As String
    7.     'if the value in this combo box is null, then show all records
    8.     If IsNull(Me.cboGenre.Value) Then
    9.         strGenre = "Like '*'"
    10.     Else
    11.         strGenre = "='" & Me.cboGenre.Value & "'"
    12.     End If
    13.      'if the value in this combo box is null, then show all records
    14.     If IsNull(Me.cboPlatform.Value) Then
    15.         strPlatform = "Like '*'"
    16.     Else
    17.         strPlatform = "='" & Me.cboPlatform.Value & "'"
    18.     End If
    19.     'combining criteria to form a WHERE clause
    20. strFilter = "[Genre] " & strGenre & " AND [PlatformID] " & strPlatform
    21.    
    22.     With Reports![rptTopRented]
    23.          .Filter = strFilter
    24.          .FilterOn = True
    25.     End With
    26.  
    27. End Sub


    I keep getting the same 'Type Mismatch' errors.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    8

    Re: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    specifically; cboPlatform refers to a field on a table thats; Data Type: Number Field size: Number

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    8

    Re: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    Forget it, it worked! THANK YOU!

  8. #8
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    Great, don't forget to mark your post as resolved...
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  9. #9

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    8

    Re: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    Just one more thing, what do i insert to display the report so it only shows the MAX value of a field?

    What do i need to add to this?

    VB Code:
    1. strFilter = "[Genre] " & strGenre & " AND [Platform] " & strPlatform

  10. #10
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    You need to change the Query (or SQL statement) that underlies to report to add a Max() to the column that you need to aggregate. All other columns will need to be included in the GROUP BY clause of the query.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  11. #11

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    8

    Re: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    SO in the query, I would add 'Max()' to the criteria of the field I want to show the max value?


    This is what I have tried so far. for field 'A' I used a count function, I save that query. And then Loaded that same query to make another query. I then dragged field 'A' in, and then grouped it by MAX and included other fields like 'Gametitle' yet, it still says the same as it did without the MAX inserted. It just doesn't show the highlest value. Nor does it show the lowest when set on MIN. Do i need to insert it into the criteria instead?

  12. #12
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    Can you post the SQL for your Query?
    Open the query, then select View\SQL.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  13. #13

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    8

    Re: ACCESS - Need to tweak 2 lines of code to cater for Numerical Data

    Quote Originally Posted by DKenny
    Can you post the SQL for your Query?
    Open the query, then select View\SQL.

    SELECT Count(tblRentalHistory.RentID) AS CountOfRentID, tblRentalHistory.GameID, tblRentalHistory.GameTitle, tblRentalHistory.Genre, tblRentalHistory.ESRB, tblRentalHistory.RentalPrice, tblRentalHistory.PlatformID
    FROM tblRentalHistory
    GROUP BY tblRentalHistory.GameID, tblRentalHistory.GameTitle, tblRentalHistory.Genre, tblRentalHistory.ESRB, tblRentalHistory.RentalPrice, tblRentalHistory.PlatformID;

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