 |
| 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
|
|
|
|

June 5th, 2006, 08:35 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Query Help pls
Hi guys Please help me with this query:)
Whenever i run this query it gives an error>>(Syntax Error converting Datetime from character String).
SELECT dbo.Patient_Info.Kpaids_num, dbo.Patient_Info.Docket_num, dbo.Patient_Info.First_Name, dbo.Patient_Info.Last_Name,
dbo.Patient_Info.Home_Number, dbo.Scheduled_Appointment.App_Date, dbo.Scheduled_Appointment.App_Time, dbo.Scheduled_Appointment.clinic,
dbo.Scheduled_Appointment.Visit
FROM dbo.Patient_Info RIGHT OUTER JOIN
dbo.Scheduled_Appointment ON dbo.Patient_Info.Kpaids_num = dbo.Scheduled_Appointment.Kpaids_num
WHERE (dbo.Scheduled_Appointment.App_Date = CONVERT(datetime, '[forms]![Appointments_View].[Text1]', 101))
|
|

June 5th, 2006, 11:03 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Ah, you have a SQL back end, and are referring to an Access date format.
What I have done is take the Access date first, and convert it to a SQL date format using regular expressions. Then you can use it to parameterize the query.
Example:
Dim sMyDate As String
Dim mm As String
Dim dd As String
Dim yyyy As String
sMyDate = Me.Text1
mm = Left(sMyDate, 2)
dd = Right(Left(sMyDate, 5), 2)
yyyy = Right(sMyDate, 4)
sMyDate = yyyy & "-" & mm & "-" & dd
...
WHERE(dbo.Scheduled_Appointment.App_Date = sMyDate)
Does this work? I don't know what your SQL date format is.
mmcdonal
|
|

June 5th, 2006, 11:05 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Alternatively, you can do this:
DateArray = Split(sMyDate, "/")
Then get your month, day and year values, check for length, add zeros, etc.
HTH
mmcdonal
|
|

June 5th, 2006, 11:18 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The alternative using Split(sMyDate, "/") is the one to use. The first method will fail if a date is entered without leading zeros, such as "6/5/06".
On the other hand. You could take the text string containing the date. Convert it to a date. Then use the Month(), Day() and Year() or DatePart() functions to extract the various parts before building the SQL Server query.
Rand
|
|

June 5th, 2006, 11:22 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Yeah, I thought of the leading zeros issue and made the second post. In the database I am running with this function, the dates are all in the format yyyy-mm-dd and always with leading zeros, so the first method works fine.
mmcdonal
|
|

June 5th, 2006, 11:27 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
We use both Access and SQL Server in house. I've had to deal with this problem too many times. It would be handy if Access had an option to use SQL Server wild cards and formatting instead of the old DOS wild card characters.
Rand
|
|

June 5th, 2006, 11:44 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ok guys thx for the responses, i'm gonna try these new options.
|
|

June 5th, 2006, 12:29 PM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm actually looking for a solution tht works with a Query in the Back-end, this query function is to generate a list based on a Date value entered in the form. so in essence i want to create a query with the WHERE CONDiTION reading a date value from an input box "Text1".
the data type used for the Date is "Datetime".
|
|
 |