Solved

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

Posted on 2006-10-26
2
170 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
  • 2
2 Comments
 
LVL 44

Expert Comment

by:Leigh Purvis
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now