Solved

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

Posted on 2006-10-26
2
178 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

631 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