i need code vba to combind two paths: the first path is located in table named da with…
- User
i need code vba to combind two paths: the first path is located in table named da with field named مكان حفظ الارشيف the second pathis in the field سند التحويل من قسم المالية in table الطلبات No relationship between to tabels Boutton to open full path folder without file .
- Assistant
Here is a sample VBA code that combines two paths and opens the specified folder using a button click:
Private Sub CommandButton_Click() Dim db As Database Dim rs1 As Recordset Dim rs2 As Recordset Dim folderPath1 As String Dim folderPath2 As String Dim combinedPath As String ' Set the database object Set db = CurrentDb ' Get the first path from the 'da' table Set rs1 = db.OpenRecordset("SELECT [مكان حفظ الارشيف] FROM [da]") folderPath1 = rs1.Fields(0).Value rs1.Close ' Get the second path from the 'الطلبات' table Set rs2 = db.OpenRecordset("SELECT [سند التحويل من قسم المالية] FROM [الطلبات]") folderPath2 = rs2.Fields(0).Value rs2.Close ' Combine the two paths combinedPath = folderPath1 & "\" & folderPath2 ' Open the folder path Shell "explorer.exe " & combinedPath, vbNormalFocus End SubPlease make sure to replace
[مكان حفظ الارشيف],[da],[سند التحويل من قسم المالية], and[الطلبات]with the actual field and table names in your database. - User
another code without Dim db As Database because it yellow error
- Assistant
If you are getting a yellow error on the line
Dim db As Database, it suggests that you might not have a reference to the "Microsoft Office xx.x Access Database Engine Object Library" added to your project.To resolve this error, you can directly use the
OpenDatabasefunction to open the database instead of creating aDatabaseobject.Here's an updated code snippet without using
Dim db As Database:Private Sub CommandButton_Click() Dim rs1 As Recordset Dim rs2 As Recordset Dim folderPath1 As String Dim folderPath2 As String Dim combinedPath As String ' Get the first path from the 'da' table Set rs1 = OpenRecordset("SELECT [مكان حفظ الارشيف] FROM [da]") folderPath1 = rs1.Fields(0).Value rs1.Close ' Get the second path from the 'الطلبات' table Set rs2 = OpenRecordset("SELECT [سند التحويل من قسم المالية] FROM [الطلبات]") folderPath2 = rs2.Fields(0).Value rs2.Close ' Combine the two paths combinedPath = folderPath1 & "\" & folderPath2 ' Open the folder path Shell "explorer.exe " & combinedPath, vbNormalFocus End Sub
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.