我有一个包含 4 个字段的 simple_table:a、b、x、P
我正在尝试根据使用其他字段作为输入参数的函数的输出来更新字段 p。在这种情况下,该函数是一个 excel 函数。我使用的是 SQL 服务器,但确实需要访问一些统计功能。所以昨天我第一次打开了访问权限。哎呀。我花了最后一天尝试学习 vba 并遵循有关记录集的各种教程。
我正在努力解决的问题是如何根据其他字段更新 P 字段?在一个循环?
非常感谢。
Dim objExcel As Excel.Application
Set objExcel = CreateObject("Excel.Application")
'Test it works
MsgBox objExcel.Application.BetaDist(0.4, 2, 5)
'OK, that works :)
'set up the ADO stuff
Dim cnn1 As ADODB.Connection
Dim MyRecordSet As New ADODB.Recordset
Set cnn1 = CurrentProject.Connection
MyRecordSet.ActiveConnection = cnn1
'Load data into MyRecordSet
MySQLcmd = "SELECT * FROM simple_table"
MyRecordSet.Open MySQLcmd
'HELP WITH THE NEXT BIT PLEASE!
'Some kind of loop to go through the recordset to set the field P
' equal to the result of the excel function betadist(x,a,b)
'I imagine looping through something like the following semi pseudo code ???
myRecordSet.Fields(“P”).Value = objExcel.Application.BetaDist(myRecordSet.Fields(“x”).Value, myRecordSet.Fields(“a”).Value, myRecordSet.Fields(“b”).Value)
'end of the loop
objExcel.Quit
Set objExcel = Nothing
MyRecordSet.Close
cnn1.Close
Set MyRecordSet = Nothing
Set cnn1 = Nothing