0

私のマスター データベースには、2 つの日付と ID 番号を含む小さなテーブルがあります。このテーブルを使用してクエリを更新し、分析を行います。テーブルは次のようになります。

Number   | Date  
1        | 09.07.2012.  
2        | 10.07.2012.

私がやりたいことは、起動後にフォームをポップアップするExcelファイルを用意することです。

そのフォームには、2 つのフィールドと 2 つのボタンが含まれている必要があります。これらのフィールドに2つの日付を入力し(日付ピッカーなどを使用)、最初のボタンでAccessの言及されたテーブルを新しいデータで更新し(古い日付を削除して新しい日付で更新)、もう1つのボタンでそのAccessデータベースで定義済みのマクロを開始します.

これはどれほど複雑ですか?解決策を教えてもらえますか?いくつかのサンプル コードは優れています。

Command25_Click() 
CurrentDb.Execute "DELETE * FROM Datumi" 
Dim tbl As Recordset 

Set tbl = CurrentDb.OpenRecordset("Datumi") 
tbl.AddNew tbl!brojka = "1" 
tbl!datum = Text8.Value 
tbl.Update 
tbl.AddNew tbl!brojka = "2" 
tbl!datum = Text10.Value 
tbl.Update
4

1 に答える 1

0

保存されたクエリを実行する方法を示すために日付の更新を使用しているため、これはある程度まで進んでいます。

'SQL for stored query, this assumes you
'will be updating based on some key
UPDATE DatesTable t
SET t.Date1 = [@Date1], t.Date2 = [@Date2]
WHERE t.aAuto=[@Key]

'Code for Excel
'You could set a library reference to 
'Microsoft ActiveX Data Objects x.x Library
Dim cmd As Object
Dim cn As Object

Set cmd = CreateObject("ADODB.Command")
Set cn = CreateObject("ADODB.Connection")

'Connection string, see also http://connectionstrings.com
strCon = "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=z:\docs\test.accdb"

cn.Open strCon

'Name of the saved query
cmd.CommandText = "UpdateDates"
cmd.CommandType = adCmdStoredProc
cmd.ActiveConnection = cn

'Some parameters.
'http://www.w3schools.com/ADO/met_comm_createparameter.asp
'Make sure you get the type right, you will find details here:
'http://www.w3schools.com/ADO/ado_datatypes.asp
'You will find direction here:
'http://www.w3schools.com/ado/prop_para_direction.asp

'Make sure you get the order right
'adDate = 7, adInteger = 3, adParamInput = 1
cmd.Parameters.Append cmd.CreateParameter("@Date1", 7, 1, , txtDate1)
cmd.Parameters.Append cmd.CreateParameter("@Date2", 7, 1, , txtDate2)
cmd.Parameters.Append cmd.CreateParameter("@Date2", 3, 1, , MyUniqueKey)

'recs : return for records affected
'adExecuteNoRecords = 128 : no records are returned by this query, 
'so this increases efficiency
'http://www.w3schools.com/ADO/ado_ref_command.asp

cmd.Execute recs,,128

'Did it work?
MsgBox "Records updated: " & recs 
于 2012-07-10T11:13:53.843 に答える