Solved

Add a value to a combobox in Access Project Sql Server Backend

Posted on 2006-10-26
2
177 Views
Last Modified: 2011-09-20
I am work with this script that I found on this site however I am getting an error at this point in the script.

Set RS = MyDataBase.OpenRecordset("dbo.Client")

I can get it to respond and open a msg/input box where I can add the the new item to Client_Name  (a text Field column two).  The combo box is bound to column one Client_ID(autonumber) and the table is Client.  What I need is for the person to be able to add a new item to this lookup table if it does not exist and choose that item.



The full script is


Private Sub Targeted_Customers_AfterUpdate()
Customer_ID_Update = Date

Dim ListData As String, Message As String
Dim MyDB As Database, RS As Recordset

If [Targeted_Customers].Column(1) = "<Add New Item>" Then

    Message = "Please Enter a New Item"    ' Set prompt.
    ' Display message
    ListData = InputBox(Message)

If Not IsNull(ListData) Then

Set MyDataBase = CurrentDb()
Set RS = MyDataBase.OpenRecordset("dbo.Client")

RS.AddNew
    RS("Client_Name") = ListData
RS.Update

RS.Close
Set RS = Nothing
db.Close
Set db = Nothing

End If

[Targeted_Customers].Requery  '<----Updates the list

End If




End Sub
0
Comment
Question by:peggyweber
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17810915
That's DAO code - none of which will work in an ADP.
I take it your want an ADO equivalent?

(btw - IMHO if you're venturing into ADP development - you should give yourself a reasonable grounding in ADO first - unless you intend to use nothing but default functionality - which again I thinkis a mistake with server data.  But then I guess professional developers exist for a reason :-)
0
 
LVL 44

Accepted Solution

by:
Leigh Purvis earned 250 total points
ID: 17810930
Private Sub Targeted_Customers_AfterUpdate()
Customer_ID_Update = Date
Dim ListData As String

If [Targeted_Customers].Column(1) = "<Add New Item>" Then

    Message = "Please Enter a New Item"    ' Set prompt.
    ' Display message
    ListData = InputBox(Message)
    CurrentProject.Connection.Execute "INSERT INTO dbo.Client (Client_Name) VALUES '" &  ListData & "'"

End If

[Targeted_Customers].Requery
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question