Re: linking databases



"Kevin" <Kevin@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E0717AF5-37EE-4065-BB60-1D0C547F83CB@xxxxxxxxxxxxxxxx

Sub Country_OnExit

Dim sSQL as String

sSQL = "UPDATE [ctbto table 1] SET " & _
" [Region] = '" & Me.chrRegion & "', " & _
" [Country] = '" & Me.chrCountry & "'" & _
" WHERE [ID] = " & Me.dtmID & ";"

DoCmd.SetWarnings False
CurrentDb.Execute sSQL
DoCmd.SetWarnings True

End Sub

However, I'm quite obviously still doing something wrong and
misunderstanding how this code is supposed to work as when I run it, it
deletes the entry on the form in the first database for the particular
country whose record I want to update, while not updating the second
table.
I've also tried using the "After Update" event property and deleting the
"On
Exit" event property in the code, but then I get compile errors.

Not sure I see how that could delete any entries from a database.

Yes, if you point to the wrong table, and that wrong table happens to have
fields named "Region" and "Country", you'd end up overwriting the record
that has that ID, but an Update statement cannot delete data.

Also, how do I let Access know where to find the relevant table in the
second database? I've tried linking that table but to no effect. Please
bear
with me here, I'm really not very proficient with SQL and VBA programming
though I'm trying to learn them. I hope you can understand my explanation
and
can tell me what I"m doing wrong.

You could use an IN clause:

sSQL = "UPDATE [ctbto table 1] " & _
"IN C:\Folder\File.MDB " & _
" SET [Region] = '" & Me.chrRegion & "', " & _
" [Country] = '" & Me.chrCountry & "'" & _
" WHERE [ID] = " & Me.dtmID & ";"


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)



.



Relevant Pages

  • Re: linking databases
    ... Sub chrCountry_AfterUpdate ... Dim sSQL As String ... a compile error there, nor do I know what else I could use there. ... database I'm trying to update). ...
    (microsoft.public.access.externaldata)
  • Re: linking databases
    ... Sub chrCountry_AfterUpdate ... Dim sSQL As String ... Using either the After Update event procedure of the Form or the Exit or ... database I'm trying to update). ...
    (microsoft.public.access.externaldata)
  • Re: What is the name of the Language we are using & recommend book
    ... Can I have 2 sub forms in a form that are not sub forms of the other sub ... As for my process I am trying to create my Access Database in shells like ... QSL or Microsoft SQL Server Data Engine or what. ... language of queries, and the query design grid is just a tool to construct ...
    (microsoft.public.access.formscoding)
  • Re: Custom Login Screen
    ... Private Sub cmdLogin_Click ... On Error GoTo ErrorHandler ... You will need to enter your full path to the database file and MDW file in the appropriate places. ... Now make an MDE file from this MDB. ...
    (microsoft.public.access.security)
  • Re: Jeff C
    ... properly secure an Access database. ... Private Sub Form_Open ... Resume ExitPoint ... Dim db As DAO.Database ...
    (microsoft.public.access.formscoding)

Loading