我正在尝试创建一个程序,将导入电子表格和附加/更新它到我的MainDB,我完成了更新过程,如果字段(JobName)是在主数据库中发现,然后我将更新记录/s。下一步是,检查记录是否存在,如果不存在,然后我需要一个代码来添加,请帮助!
ConnectdbMain 'Sub Where I connect to my Maindb
Connectdbtemp 'Sub Where I connect to Tempdb which I imported to an excelfile
With rs
While Not .EOF
rst.MoveFirst
While Not rst.EOF
If .Fields(Combo.Value) = rst.Fields(Combo2.Value) Then 'the user is allowed which field is to compare and append I use combo box to filter choices.
.Edit
.Fields(Combo3.Value) = rst.Fields(Combo4.Value)
.Update
End If
rst.MoveNext
Wend
.MoveNext
Wend
End If
CloseDbMain
Set rst = Nothing
Dbs.Execute "DROP TABLE TempTable" 'I drop it like a trash since its already appended :)
ClosedbTemp
End With发布于 2014-03-09 14:37:26
嗯..。我不知道你怎么样。但如果是excel电子表格,我会使用OLE DB读取电子表格数据源,并使用SQL query首先选择电子表格中所有不同的JobName。
我还将使用for in loop for with电子表格唯一名称,以便使用VBA在主数据库中执行select语句,以便...
从表中选择计数( JobName ),其中JobName= the_job_name_in_excel
然后使用If Then来检测返回的行数是否为0,然后执行一条update语句。
当然,还有更多,所以如果您想使用我的方法,那么您需要阅读如何创建到主数据库和电子表格的数据库连接。创建这些连接的方法在那里很容易获得。
https://stackoverflow.com/questions/22279054
复制相似问题