Opening a file

sven2

Registered User.
Local time
Today, 22:24
Joined
Apr 28, 2007
Messages
297
Hello,

in my database I have to open a word document by pussing a button.
Now the location of the word file is hardcoded.

Something like c:\database\test.doc

I would like to change this in such a way that everybody can change this location (in a form).

Do I have to store this location therefore in a table or are there other ways to do this (for example something like a public function?)

Sven.
 
If you want it to be dynamic, where someone can change it, store it in a table and then you can use a SQL statement or DLookup to pull it when you need it.
 
Do you call a public function to open the document? You could add a parameter for the file location of the Word Document.
D
 
Something like below would do the trick

Code:
Public Sub OpenDoc(Path As String)
    Dim objWrd As Object
    Dim docWrd As Object
    Dim strPath As String

    strPath = Path

    Set objWrd = CreateObject("Word.Application")
    Set docWrd = objWrd.Documents.Open(strPath)


    Set objWrd = Nothing
    Set docWrd = Nothing

End Sub
 
Hello,

I put everything in a table and now I want to make my SQL:

UPDATE Bestandlocaties SET Bestandlocaties.Locaties = [Forms]![FrmBeveiligingsbeheer]![txtuitnodiging]
WHERE (((Bestandlocaties.NummerId)=1));

i change it into

strSQL = " UPDATE Bestandlocaties SET Bestandlocaties.Locaties =" & [Forms]![FrmBeveiligingsbeheer]![txtuitnodiging] & " WHERE (bestandlocaties.nummerID)=1;"

And I always get an error too few parameters expected 1

Can somebody help me with this?

Thanks in advance,
Sven.
 
Hello,

I put everything in a table and now I want to make my SQL:

UPDATE Bestandlocaties SET Bestandlocaties.Locaties = [Forms]![FrmBeveiligingsbeheer]![txtuitnodiging]
WHERE (((Bestandlocaties.NummerId)=1));

i change it into

strSQL = " UPDATE Bestandlocaties SET Bestandlocaties.Locaties =" & [Forms]![FrmBeveiligingsbeheer]![txtuitnodiging] & " WHERE (bestandlocaties.nummerID)=1;"

And I always get an error too few parameters expected 1

Can somebody help me with this?

Thanks in advance,
Sven.

Try this

strSQL = " UPDATE Bestandlocaties SET Bestandlocaties.Locaties =" & [Forms]![FrmBeveiligingsbeheer]![txtuitnodiging] & " WHERE [bestandlocaties].[nummerID]=1;"
 
Hello,

I still get an error 3075 syntaxiserror ...

I don't understand why but I think it has something to do with the fact that I update a string like "c:\database\documenten\test.doc"
 
Last edited:
Hello,

I really don't understand this at all:

Below a working query:

UPDATE Bestandlocaties SET Bestandlocaties.Locaties = [Forms]![FrmBeveiligingsbeheer]![txtuitnodiging]
WHERE (((Bestandlocaties.NummerId)=1));

If I change this in a string it doensn't work? Why?

Best regards,
Sven.
 
Hello,

I tried several things but this is the last sql:

Private Sub txtuitnodiging_AfterUpdate()

Dim strSQL As String

strSQL = " UPDATE Bestandlocaties SET Bestandlocaties.Locaties =" & [Forms]![FrmBeveiligingsbeheer]![txtuitnodiging] & " WHERE (((Bestandlocaties.NummerId)=1)); "

End Sub

Sven.
 
This isn't running the SQL it's just assigning it to the string. You need to run it before it will work with either:

Code:
strSQL = "UPDATE Bestandlocaties SET Bestandlocaties.Locaties =" & [Forms]![FrmBeveiligingsbeheer]![txtuitnodiging] & " WHERE (((Bestandlocaties.NummerId)=1))"

CurrentDb.Execute strSQL, dbFailOnError

Or with

Code:
strSQL = "UPDATE Bestandlocaties SET Bestandlocaties.Locaties =" & [Forms]![FrmBeveiligingsbeheer]![txtuitnodiging] & " WHERE (((Bestandlocaties.NummerId)=1))"

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True

If you use the second option, be sure to put an error handler into your event and make the first line of your error handler:

DoCmd.SetWarnings True

Or else you might find yourself without any warning messages at all.
 
Hello,

indeed I forgot to copy the currentdb.execute strsql to the website but anyway I still get an error when executing the strsql syntaxiserror operator is missing.

Sven.
 
Have you tried the second one? Sometimes that will work where the other does not (the other has problems with parameters).
 
is the Bestandlocaties.Locaties field a text field? If so you need to surround the value in quotes.
 
Hello,

both give the same error ... this is a strange thing.
 
As this is getting long and drawn out, is there any way you can post your db here? If you go to Tools > Database Utilities > Compact and Repair and then zip the mdb file up with WinZip, or something similar, you can upload it if the final zipped size is 393Kb or less.
 
Hello,

I have made the example. If you open the form, change the first field and go to the second the sql is giving an error!

Thanks in advance,
Sven.
 

Attachments

Users who are viewing this thread

Back
Top Bottom