Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2007, 12:48 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

What are the defaults for the date combos? Try this:

If IsNull(Me.cboStartDate) Then
   stLinkCriteria = stLinkCriteria & ""
Else
   dtStart = Me.cboStartDate
End If
If IsNull(Me.cboEndDate) Then
   If dtStart <> "" Then
      MsgBox "Please select End Date."
      Exit Sub
   End If
Else
   dtEnd = Me.cboEndDate
End If



mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old October 23rd, 2007, 01:15 PM
Authorized User
 
Join Date: Sep 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

RowSrc: SELECT qryrptAllQuotesByRep.CreatedDate FROM qryrptAllQuotesByRep;
Columns: 1
Bound Col: 1
Enabled: Yes
Locked: No

No Events
 
Old October 23rd, 2007, 01:16 PM
Authorized User
 
Join Date: Sep 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Didn't work with the new date code !
 
Old October 23rd, 2007, 01:21 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Try this then, this is all I can thik of without having the database in front of me:

If dtStart <> "" And dtEnd <> "" Then
   If stLinkCriteria <> "" Then
      stLinkCriteria = stLinkCriteria & " AND [CreatedDate] BETWEEN " & dtStart & " AND " & dtEnd
   Else
      stLinkCriteria = "[CreatedDate] BETWEEN " & dtStart & " AND " & dtEnd
   End If
End If


Also, add this code BEFORE this section:

Msgbox dtStart & vbCrLf & dtEnd

See what the variables are taking. Then post the results.


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old October 23rd, 2007, 01:29 PM
Authorized User
 
Join Date: Sep 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK.
If I leave the dates blank I get a type mismatch, If I select both dates, it displays the dates and on ok I get type mismatch.
If I select cboStartDate only I get type mismatch, but if I select cboEndDate only it displays time and date and the the type mismatch.
 
Old October 23rd, 2007, 05:49 PM
Authorized User
 
Join Date: May 2007
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

have you put an input mask on cbostartdate and cboenddate?

Private Sub btnsearchmortginspect_Click()

    On Error GoTo errorhandler

    Dim strSQL As String 'string to store the sql
    Dim varwhere As Variant
    Dim intrcount As Integer

    'user wants to do a search

    strSQL = "INSERT INTO tmpmortginspsearch " & _
        "SELECT tblfileinspect.inspectid, tblfileinspect.arfirm, " & _
        "tblfileinspect.aradviserid, tblfileinspect.clientname1, " & _
        "tblfileinspect.clientname2, tblfileinspect.subdate, tblfileinspect.lender, " & _
        "tblfileinspect.compdate, tblfileinspect.status " & _
        "FROM tblfileinspect WHERE "

    'if there is a submission date
    If Not IsNothing(dtsubdatesearch) Then
        varwhere = "(subdate >= #" & Me.dtsubdatesearch & "#)"
    Else
        varwhere = "(subdate >= date()-180)"
    End If

    'if there is a completion date
    If Not IsNothing(dtcompdatesearch) Then
        varwhere = (varwhere + " AND ") & _
            "(compdate <= #" & Me.dtcompdatesearch & "#)"
    End If

    'if there is an ar firm
    If Not IsNothing(cboarnamesearch) Then
        varwhere = (varwhere + " AND ") & _
            "(arfirm=" & Me.cboarnamesearch & ")"
    End If

    'if there is an adviser
    If Not IsNothing(cboadvisersearch) Then
        varwhere = (varwhere + " AND ") & _
            "(aradviserid=" & Me.cboadvisersearch & ")"
    End If

    'if there is a lender
    If Not IsNothing(cbolendersearch) Then
        varwhere = (varwhere + " AND ") & _
            "(lender like '" & Me.cbolendersearch & "*')"
    End If

    'if there is a client name
    If Not IsNothing(txtclientname) Then
        varwhere = (varwhere + " AND ") & _
            "(clientname1 Like '" & Me.txtclientname & "*') "
        varwhere = (varwhere + " OR ") & _
            "(clientname2 Like '" & Me.txtclientname & "*') "
    End If



There's alot more to the procedure however it works fine for me, allowing for multiple options of search entries. Hope this is of some help to you

 
Old October 24th, 2007, 12:46 AM
Authorized User
 
Join Date: Sep 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Jeremy, I did have input masks on the source table for cboStartDate and cboEndDate.

I've created a basic test environment without the input masks but am still getting the mismatch.

Thanks for the sample code, I will try to adapt that to my structure and give it a go.


Dave
 
Old October 24th, 2007, 07:13 AM
Authorized User
 
Join Date: May 2007
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The key with that sample code is that the tmpmortgsearch table it refers to is a carbon copy of the table that the query is searching.

For some reason access just doesn't like taking only part of the results and inserting into a temporary table






Similar Threads
Thread Thread Starter Forum Replies Last Post
Special Formatting in MS Access Report via VBA alforddbu VB Databases Basics 9 December 20th, 2007 04:14 PM
Form Criteria for Report MArgente Access 10 June 8th, 2007 12:30 PM
Generating report via VBA in Access gurkie Access 2 July 16th, 2006 02:16 PM
Subtotals in access report using vba bogaerts Pro Visual Basic 2005 0 January 30th, 2006 08:33 AM
Need help creating word report from Access VBA emapis Access VBA 2 November 10th, 2004 05:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.