Link to home
Start Free TrialLog in
Avatar of RichFrot
RichFrotFlag for United States of America

asked on

Variable date from inputbox in SQL Statement

SQL syntax on variable date, I believe to be incorrect in "Where" statement.  The following is the code:

Dim txtNewHireFromDate As String

txtNewHireFromDate = InputBox("Enter New Hire From Date. Use mm/dd/yyyy format: ")
If StrPtr(txtNewHireFromDate) = 0 Then
    MsgBox "You need to input a date"
End If

SQLQuery = "Select tblEmployee.EmployeeID, tblEmployee.FirstName, tblEmployee.MiddleName, tblEmployee.LastName, tblEmployee.HomeAddress1, tblEmployee.city, tblEmployee.state, tblEmployee.ZipCode, tblEmployee.HireDate " _
& "FROM tblEmployee " _
& "WHERE tblEmployee.HireDate > '& # & txtNewHireFromDate & # & 'or tblEmployee.RehireDate > '& # & txtNewHireFromDate & # & '; "
rst.Open SQLQuery, cnn, adOpenKeyset, adLockOptimistic
Avatar of Joe Overman
Joe Overman
Flag of United States of America image

Your where should be:

'WHERE ((tblEmployee.HireDate>#' & txtNewHireFromDate & '#) AND (tblEmployee.HireDate >#' & txtNewHireFromDate & '#))'
ASKER CERTIFIED SOLUTION
Avatar of Joe Overman
Joe Overman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RichFrot

ASKER

Thank you for the prompt responce