Hey guys, I have a project i am working on and needed to create a way to transfer the data in a table to another file. I got it working with the following code
However, I've been banging my head trying to figure out how to link a file location as a string in this code. What i'm trying to do is instead of having the file location written in the code (highlighted in red above), I would like the file location/name to be a string so users can select where the new database is. I already made a command button to select a file and link it and the file path to a text box on the same form that this code is written on. I've tried linking it as a sting but can't seem to get it working.
I'm not super savvy with access yet. I know enough to get around and can usually search the web to find answers to most of the questions i get. But i cant figure this one out..
Any help would be greatly appreciated.
Code:
Private Sub Transbtn_Click()
Dim dbs As DAO.Database, strsql As String
Set dbs = CurrentDb
strsql = "INSERT INTO [table1] ( [Date In], [Time In], Type, Amount, [From], Reason, Description, [Transfer #], [Received From], [Received By], [Date Out], [Rel To], [Rel By] ) [COLOR="Red"]IN 'E:\stuff\MyFile.accdb'[/COLOR] " & vbCrLf & _
"SELECT [Table1].[Date In], [Table1].[Time In], [Table1].Type, [Table1].Amount, [Table1].From, [Table1].Reason, [Table1].Description, [Table1].[Transfer #], [Table1].[Received From], [Table1].[Received By], [Table1].[Date Out], [Table1].[Rel To], [Table1].[Rel By] " & vbCrLf & _
"FROM [Table1];"
dbs.Execute strsql
End Sub
However, I've been banging my head trying to figure out how to link a file location as a string in this code. What i'm trying to do is instead of having the file location written in the code (highlighted in red above), I would like the file location/name to be a string so users can select where the new database is. I already made a command button to select a file and link it and the file path to a text box on the same form that this code is written on. I've tried linking it as a sting but can't seem to get it working.
I'm not super savvy with access yet. I know enough to get around and can usually search the web to find answers to most of the questions i get. But i cant figure this one out..
Code:
Private Sub Transbtn_Click()
Dim strdest As String
Dim dbs As DAO.Database, strsql As String
Set dbs = CurrentDb
strdest = Me.upfile
strsql = "INSERT INTO [table1] ( [Date In], [Time In], Type, Amount, [From], Reason, Description, [Transfer #], [Received From], [Received By], [Date Out], [Rel To], [Rel By] ) [COLOR="Red"]IN strdest[/COLOR] " & vbCrLf & _
"SELECT [Table1].[Date In], [Table1].[Time In], [Table1].Type, [Table1].Amount, [Table1].From, [Table1].Reason, [Table1].Description, [Table1].[Transfer #], [Table1].[Received From], [Table1].[Received By], [Table1].[Date Out], [Table1].[Rel To], [Table1].[Rel By] " & vbCrLf & _
"FROM [Table1];"
dbs.Execute strsql
End Sub
Any help would be greatly appreciated.