Home > Software engineering >  VB problem in excel
VB problem in excel

Time:10-13


An excel file, built a save button, click and then save the data,
The database name is the db. The MDB, and excel file folder in the same directory,
1. If you want to change the path of the database, such as the database alone in D: \ 123 folder, how to change?
2. After a database encryption, password is 456, how to add a password in program?

Private Sub CommandButton1_Click ()
Dim CNN As New ADODB. Connection
Dim RST As New ADODB. You
Dim sq1 As String
Dim x As Long
X=[a65536]. End (xlUp). Row
For I=2 To 10
CNN. Open the provider="Microsoft. Jet. The oledb. 4.0; Data source="& amp; ThisWorkbook. Path & amp; "\ db MDB
"Sq1="select * from wBGA"
RST. Open sq1, CNN, adOpenKeyset, adLockOptimistic
RST. AddNew
RST. Fields (" X ")=Range (" Q "& amp; I)
RST. Update
CNN. Close
The Set of CNN=Nothing
Next I
MsgBox "successfully saved"
End Sub

Thank you very much!

CodePudding user response:

CNN. Open the provider="Microsoft. Jet. The oledb. 4.0; Data source="& amp; ThisWorkbook. Path & amp; "\ db MDB
"Change
CNN. Open the provider="Microsoft. Jet. The oledb. 4.0; Data source="& amp; "D: \ \ 123 db. MDB", and "456"
  • Related