Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / January 2006

Tip: Looking for answers? Try searching our database.

Using CommonFileOpenSave in a relational table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paulc - 20 Jan 2006 14:23 GMT
I’m using Access 2003

The following code is called from a button on a userform.
The routine calls the CommonFileOpenSave box, prompting the user to search
and select a file on the network/local drive.

Once selected, the file and its path is captured in a string
(strInputFileName).

The String is then saved to a table (Con_DocPath) as a hyperlink in the
field (Subject)... this works fine!

The user can repeat the task, as the table is linked as a child of the
primary table.

My problem is that this routine will only place the string in the field
(Subject) programmatically and does not trigger the auto-number field in the
same record, as it would if one was to enter a new record manually. This is
causing broken links between my tables as the missing autonumber is not
establishing the record key and therefore the relationship.

Any ideas how this can be resolved?

Thank you, Paul

Dim strFilter As String
Dim strInputFileName As String
Dim strSQL As String
Dim str1SQL As String
strFilter = ahtAddFilterItem(strFilter, "Word Files (*.doc)", "*.doc")
strInputFileName = ahtCommonFileOpenSave( _
               Filter:=strFilter, OpenFile:=True, _
               DialogTitle:="Please select the documents associated with
this contract...", _
               Flags:=ahtOFN_HIDEREADONLY)

strSQL = "INSERT INTO Con_DocPath (Subject) "

strSQL = strSQL & "VALUES ('" & strInputFileName & "');"

CurrentDb.Execute strSQL
Allen Browne - 20 Jan 2006 14:56 GMT
Access should automatically supply an AutoNumber when you add a new record.

But if you have the form already open, with (say) the DocName text box in a
subform named Sub1, it might be easier to use something like this:

   Me.Sub1.SetFocus
   If Not Me.Sub1.Form.NewRecord Then
       RunCommand acCmdRecordsGotoNew
   End If
   Me.Sub1.Form.DocName.SetFocus
   RunCommand acCmdInsertHyperlink

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> I'm using Access 2003
>
[quoted text clipped - 39 lines]
>
> CurrentDb.Execute strSQL
Paulc - 20 Jan 2006 15:38 GMT
Thank you for your response.

I records added this way do not appear to to trigger the autonumber in the
table because the data is not bein placed via the form.

I figure there has to be a programmatical approach to this. Unfortunately
i'm not experienced enough to know where to place your suggestion in my code
- would it be in the existing routine, if so, where would you suggest?

I've been loking at 'sendkey' commands to in the vain hope this solution
could provoke access into providing a new key when my string is placed in the
table, but there is a lack of meanigful examples around.

Thanks,

Paul.

> Access should automatically supply an AutoNumber when you add a new record.
>
[quoted text clipped - 51 lines]
> >
> > CurrentDb.Execute strSQL
Allen Browne - 20 Jan 2006 16:44 GMT
The code I suggested could go in the Click event of a command button on your
main form, to add a new document to the subform.

The AutoNumber will be assigned when you execute an Append query statement
as per your example. (I am assuming the data is in an Access (JET) table
here.)

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Thank you for your response.
>
[quoted text clipped - 76 lines]
>> >
>> > CurrentDb.Execute strSQL
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.