Results 1 to 7 of 7
  1. #1
    jysharp2003 is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    5

    Lightbulb Access Form VBA problem

    Hi! Access question here.
    I have three entry fields in a form. VBA mouse over I see the entries except on the last line of code below. I am not sure if my concatenate of these three values are formatted right. Form runs with full content because the values are not being recognized.
    "'strrangecategory' & 'strFromDate' & 'strToDate'"
    is the troubled string I think. Entry is From thru To date with a desired category (NULL for all). UG!
    Here is the function below....can anybody help?
    +++++++++++++++++++++++++++++
    Private Sub Command99_Click()
    Dim strFromDate As String
    Dim strToDate As String
    Dim strrangecategory As String





    strFromDate = "adj_date_post >= '" & FromDate & " '"
    strToDate = "adj_date_post <= '" & ToDate & "'"
    strrangecategory = "category = '" & rangecategory & " '"



    If IsNull(rangecategory) Then
    DoCmd.Close
    DoCmd.OpenForm "search_payee_budgetchk", acNormal, , "'strFromDate' & 'strToDate'"
    Else
    DoCmd.OpenForm "search_payee_budgetchk", acNormal, , "'strrangecategory' & 'strFromDate' & 'strToDate'"
    End If



    End Sub


    Thanks!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quotes are needed not not the way you have them in the WhereCondition argument.
    Code:
    If IsNull(rangecategory) Then
       DoCmd.OpenForm "search_payee_budgetchk", , , strFromDate & " AND " & strToDate
    Else
       DoCmd.OpenForm "search_payee_budgetchk", , , strrangecategory " AND " & strFromDate " AND " & strToDate
    End If
    DoCmd.Close
    ...and notice I moved that Close statement.

  3. #3
    jysharp2003 is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    5

    Data Type Mismatch

    Thanks RuralGuy,
    Below is adjusted code. I have a data type mismatch on the line of code underlined below. Mousing over the variables it does show my entries so I think I am close. Tried changing the declaring statements to Dates but no difference. Left them as string. Any idea?

    Private Sub Command99_Click()
    Dim strFromDate As String
    Dim strToDate As String
    Dim strrangecategory As String

    strFromDate = "adj_date_post >= '" & FromDate & " '"
    strToDate = "adj_date_post <= '" & ToDate & "'"
    strrangecategory = "category = '" & rangecategory & " '"

    If IsNull(rangecategory) Then
    DoCmd.Close
    DoCmd.OpenForm "search_payee_budgetchk", , , strFromDate & " AND " & strToDate
    Else
    DoCmd.OpenForm "search_payee_budgetchk", , , strrangecategory & " AND " & strFromDate & " AND " & strToDate
    End If

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What is the FieldType of the rangecategory field?

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It looks like I might have overlooked a couple of other issues:
    strFromDate = "adj_date_post >= #" & FromDate & "# "
    strToDate = "adj_date_post <= #" & ToDate & "# "

  6. #6
    jysharp2003 is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    5

    You solved it.

    Rural. Thanks and now I can continue to work the weekend. I will close the thread.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Great! Just follow the link in my sig for an explaination on how to mark the thread as Solved.

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

Similar Threads

  1. Form problem
    By DPG in forum Forms
    Replies: 12
    Last Post: 09-17-2010, 09:05 AM
  2. Form problem
    By mc24 in forum Forms
    Replies: 3
    Last Post: 08-04-2010, 06:39 AM
  3. Form Name Problem
    By jgelpi16 in forum Programming
    Replies: 4
    Last Post: 07-22-2010, 12:56 PM
  4. Replies: 2
    Last Post: 06-14-2010, 03:25 PM
  5. Outlook Form to Access problem
    By bearsgone in forum Import/Export Data
    Replies: 1
    Last Post: 02-04-2010, 11:14 AM

Tags for this Thread

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