I need a VBA routine to add data to a field in a table

G

Guest

Using Access 2003.

I'm using the following code to invoke a the comon open dialogue box in my
form.
The user selects a file and the file path is captured in the string
strInputFileName
I need the captured path and file name to be added to the table
'Con_DocPath' in the field 'DocumentPath'.

Unfortunately, i'm only part way there and i'm looking for some guidance

The file path is captured but i need a solution that places the captured
'strInputFileName' in the table.

Each time the user repeats the above, the new file path is added to a list
box on the form showing the selection and addition was successful.

on click sub...

Dim strFilter As String
Dim strInputFileName As String
Dim strSQL As String

'strFilter = ahtAddFilterItem(strFilter, "Word Files (*.doc)", "*.doc")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select the documents...", _
Flags:=ahtOFN_HIDEREADONLY)


strSQL = "INSERT INTO Con_DocPath (DocumentPath) "
strSQL = strSQL & "VALUES(" & strInputFileName & "');"
CurrentDb.Execute strSQL

Many thanks.

Paul.
 
J

John Spencer

I'm not quite sure of everything you are doing, but you are not surrounding
your strInputFileName with quotes. That will cause and error.

strSQL = "INSERT INTO Con_DocPath (DocumentPath) "
strSQL = strSQL & "VALUES(""" & strInputFileName & """);"

My preference is to use
strSQL = "INSERT INTO Con_DocPath (DocumentPath) "
strSQL = strSQL & "VALUES(" & Chr(34) & strInputFileName & Chr(34) & ");"

That is always clearer to me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top