简体   繁体   English

通过VBA从Outlook访问Access数据库

[英]Accessing an Access DB from Outlook via VBA

The situation: 情况:

In Outlook I get a message from a server. 在Outlook中,我从服务器收到一条消息。 The content of the message needs to be put into an Access db. 消息的内容需要放入Access数据库中。 But, there may not exist another message with the same date. 但是,可能不存在其他具有相同日期的消息。 So, I need to look into a db if there is already a message with the same date and time. 因此,如果已经有一条具有相同日期和时间的消息,我需要调查数据库。 If there exists one, then it needs to be replaced and otherwise the message needs to be added to the database. 如果存在,则需要替换它,否则需要将消息添加到数据库。 The database contains a list of current positions from the vehicles on the road. 该数据库包含道路上车辆当前位置的列表。

The problem: 问题:

I have problems to compare a date time with a date time in an Access DB via VBA. 我在通过VBA在Access DB中比较日期时间和日期时间时遇到问题。 The query I use returns no records but there is a record in the database. 我使用的查询不返回任何记录,但是数据库中有一条记录。

This is the query I use: 这是我使用的查询:

  adoRS.Open "SELECT * FROM currentpositions WHERE ((currentpositions.  
  [dateLT])=" & "#" & date_from_message & "#" & ")", adoConn, adOpenStatic, adLockOptimistic

Second I need to now what the result is of that query. 其次,我现在需要该查询的结果。

How can I determine the number of records that my query gives me? 如何确定查询给我的记录数?

Thanks camastanta 感谢camastanta

If date from message is a date, try: 如果消息中的日期是日期,请尝试:

"SELECT * FROM currentpositions WHERE ((currentpositions.
[dateLT])=#" & Format(date_from_message,"yyyy/mm/dd") & "#)"

That is, format the date to year, month, day order. 也就是说,将日期格式设置为年,月,日顺序。

Does date_from_message have a time attached? date_from_message有时间吗? Does dateLT have a time? dateLT有时间吗? If so, it may be best to exclude the time, if only date is relevant. 如果是这样,最好只排除日期,否则最好排除时间。

You can get the number of records returned from the RecordCount property, but you need to use the right cursor type : 您可以获取RecordCount属性返回的记录数,但是需要使用the right cursor type

adOpenKeyset: 1 adOpenKeyset:1
adOpenStatic: 3 adOpenStatic:3

I note you are using adOpenStatic, so: 我注意到您正在使用adOpenStatic,因此:

adoRS.Recordcount

Should suit. 应该适合。

Thanks for that: the format is working but I still have the problem with the time. 谢谢您:格式有效,但是我仍然遇到时间问题。 I need to compare a date/time. 我需要比较日期/时间。

I use the date/time from the message-body to compare it with a date/time in an access database. 我使用消息正文中的日期/时间将其与访问数据库中的日期/时间进行比较。 If there exists a record with that time then I have to do nothing and otherwise I need to be add the message-body the database. 如果存在当时的记录,那么我什么都不要做,否则我需要添加消息主体数据库。

In fact I use more fields to determine if the record is existing but I have only problems with the date/time-field. 实际上,我使用更多字段来确定记录是否存在,但日期/时间字段只有问题。 The message body is like this: 10125,Road Runner,16/12/2009 18:28:00,(16/12/2009 17:28:00 UTC),11,51.32400000,3.20000000, Position report (with fields:db-number,name,date local,date utc,status,position,other) 消息正文是这样的:10125,Road Runner,16/12/2009 18:28:00,(16/12/2009 17:28:00 UTC),11,51.32400000,3.20000000,位置报告(带有字段:db -数字,名称,本地日期,utc日期,状态,位置等)

Regards Camastanta 问候卡玛斯塔塔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM