Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 31st, 2006, 01:51 PM
Authorized User
 
Join Date: Dec 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Create record in linked SQL table

Hallo,

I wanted to ask what code is required to create new records in a linked SQL table using Visual Basic. I can retreive specific data and append it but cant create new records. here is what i have at the moment:


Private Sub cmdNewReseller_Click()

Dim ws As Workspace
Dim db,curDB As Database
Dim rs_form As DAO.Recordset
Dim strConnection As String

Set ws = DBEngine.Workspaces(0)

Let strConnection = "ODBC;DSN=MagicHDIQ" & ";UID=" & "magic" _
    & ";PWD=" & "magic"

Set db = ws.OpenDatabase("", False, False, strConnection)

Set curDB = CurrentDb
Set rs_form = curDB.OpenRecordset("_SMDBA_._COMPANY_") 'this one gives error msg that table cant be found.
another alternative I tried was... (below)
Set rs_form = db.OpenRecordset("_SMDBA_._COMPANY_") 'this but get an error msg "ODBC--Call failed" at the line 'rs_form.Update' below.
rs_form.AddNew
rs_form!CODE = "test"
rs_form.Update

End Sub



Im assuming that the 'rs_form.AddNew' line has been successfully executed, but pops an error maybe because not all fields are filled in in the new record? I just populated that particular field to test if I could create a new record.

 
Old May 31st, 2006, 01:54 PM
Authorized User
 
Join Date: Dec 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Im sorry I forgot to say thank you to anyone who may shed some light on this. I hit the post button instead of preview.

anyway...

Any help or advice will be greatly appreciated, thanks for your time and help.

Derek

 
Old May 31st, 2006, 04:31 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I am not an expert by any stretch of the imagination, but the first question I would ask is... Does the table _SMDBA_._COMPANY_ currently exist in the database?

Mike
EchoVue.com
 
Old June 1st, 2006, 03:22 AM
Authorized User
 
Join Date: Dec 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi echovue,

the _SMDBA_._COMPANY_ table is a linked table from an external sql database. I currently have my fields from that table in my forms and are updated. I can add new records if I open the table directly from the database window. But I need to to be able to do this in code from the FE forms. Thanks very much.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked SQL table doesn't show up as control source halfnote5 Access 2 September 3rd, 2007 07:30 PM
deleting a record from a linked table??? tico31pl Classic ASP Basics 0 May 18th, 2006 09:58 AM
How do I write out a record to an SQL db table? furjaw Visual Basic 2005 Basics 1 April 26th, 2006 05:16 PM
Access MDB with a Linked SQL Server Table..... timmaher Classic ASP Databases 0 September 28th, 2005 03:57 AM
Access and update linked SQL Server 2000 table Lizu Access 9 May 10th, 2004 12:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.