supermaestro
Programmer
Hi. I've looked through the forums and tried a variety of solutions. Basically I have a form which asks the user for an account type, transaction type, a date from and a date to. I am trying to run the query and if there are results then a report is opened else a message is displayed. The problem is that the message is getting displayed everytime even though I know that data exists for the criterias that I am entering. It seems that the query is not calculating the dates properly between the 'from and 'to' dates entered. I have tried using BETWEEN AND along with >= <= but to no avail. The date format is a short date i.e. user enters 01/05/2003 for the 1st May 2003. The [Transaction Date] is the field in the table which I am using to see if is between the user entered dates
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.Open "SELECT * FROM contacts, transactions WHERE contacts.[Contact ID] = transactions.[Contact ID] And (contacts.[Account Type] = '" & [Forms]![Report Form Options]![Account Type] & "') And (transactions.[Last Transaction] = '" & [Forms]![Report Form Options]![Transaction Type] & "') And (transactions.[Transaction Date] BETWEEN #" & Format([Forms]![Report Form Options]![Transaction Date From], "dd/mm/yyyy"
& "# AND #" & Format([Forms]![Report Form Options]![Transaction Date To], "dd/mm/yyyy"
& "#);"
If rst.EOF And rst.BOF Then
MsgBox "There Were No Actions Between Those Dates.", vbOKOnly
Else
DoCmd.OpenReport "Reports", acViewPreview
DoCmd.Close acForm, "Report Form Options"
End If
Exit Sub
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.Open "SELECT * FROM contacts, transactions WHERE contacts.[Contact ID] = transactions.[Contact ID] And (contacts.[Account Type] = '" & [Forms]![Report Form Options]![Account Type] & "') And (transactions.[Last Transaction] = '" & [Forms]![Report Form Options]![Transaction Type] & "') And (transactions.[Transaction Date] BETWEEN #" & Format([Forms]![Report Form Options]![Transaction Date From], "dd/mm/yyyy"
If rst.EOF And rst.BOF Then
MsgBox "There Were No Actions Between Those Dates.", vbOKOnly
Else
DoCmd.OpenReport "Reports", acViewPreview
DoCmd.Close acForm, "Report Form Options"
End If
Exit Sub