Open database in Excel VBA

dollygg

New Member
Joined
Jul 21, 2010
Messages
46
Hello,

For some reason I get stuck right on the frist line of code. I am looking for some sample code that allow me to extract data from the database.

Sub UpdateDB()
'Writes records to database
Dim db1 As Database
Dim rs1 As Recordset
dBase = "C:\Documents and Settings\qguan\Desktop\481\SignoffLog"
Set db1 = OpenDatabase(dBase)
Set rs1 = db1.OpenRecordset("Select * from SignoffLog where AnalystSignoffDate = Date() and CheckboxName= """ & mychkbox & """")
If rs1.RecordCount() > 0 Then
MsgBox "Start editing existing record into the database"
With rs1
.Edit
'!CheckboxName = mychkboxname
!ReviewerSignoffDate = Date
!Reviewer = UserId()
.Update
End With
Else
MsgBox "Start adding new record into the database"
With rs1
.AddNew
!CheckboxName = "" 'mychkboxname
!AnalystSignoffDate = Date
!Analyst = UserId()
.Update
End With
End If
db1.Close
Set rs1 = Nothing
Set db1 = Nothing
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,224,578
Messages
6,179,654
Members
452,934
Latest member
mm1t1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top