?
Solved

Adding New Records Events in Access and SQL Query

Posted on 2004-09-14
7
Medium Priority
?
298 Views
Last Modified: 2006-11-17
Hi Every Body
I have a question on Forms.
I am using Access in order to make my Forms and I am using SQL server for DataBase.
Here is the Scenario:
Basically I want to know what event happens when one uses the Add New Button on the Navigation Bar (the Bar on the Button of Every form which let’s you to go back and forth and Add a new data to your Table)?
I have a form, which we Call it F1 and it’s Record Source is Q1 Query, I know how to send some Data from it to another Table Table1 using a Command Button and Some VB Coding in it’s OnClick Event, But I want to be able to send the same Data when I want to add a new data to my F1 Form, without using my Button. Any suggestion?

Best Regards
Sanan

Also on the same Note the Data that I want to send is the Data that comes from a subform “SF1” on my F1 Form, Rather than Pick them one by one, I want to run a Following SQL query on this SUBForm “SF1” :
SELECT     OrderID, ProductID, UnitPrice, Quantity, Discount
FROM         [Order Details]
WHERE     (OrderID =         )
On the Where condition I want to say that Basically the OrderID is the same as the Original F1 Order ID.
How can I do that?
And After it is done Append the Result Row or Rows to my table1 Table.
How can I do it?

Best regards
Sanan
0
Comment
Question by:Bijanbijan
  • 4
  • 3
7 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 12053749
Hello Bijanbijan,

The addnew button just positions you into an empty record it doesn't save a new (even empty) record.  The record is not saved until you move away from it or otherwise do a save record action provided you have enetred some data.
The only event that will fire for the new record is the form_current event, although other events may fire to complete the processing of the record that was on the screen before you clicked the add new button.

Are you saying that you want to save the record that you are about to enter into 2 different tables?
This does not sound like good design, on the face of it.

Pete
0
 

Author Comment

by:Bijanbijan
ID: 12061662
Hi Pete
Thanks for reply.
What I want to do is simple; basically As I explained Before,
I have a form, which we Call it F1 and it’s Record Source is Q1 Query, I know how to send some Data from it to another (not related) Table Table1 using a Command Button and Some VB Coding in it’s OnClick Event, Her is the new Scenario, Also by pushing the same Button I want to be able to do what ever the Navigation Button does (add new data Button Off Course), which is Updatting my Original Q1 query (and Tables) and Moving to a New Record.
Or I can use the add new Button of Navigation Bar, to do what it supposed to do, also on top of it to add the all or some of data to my Extra Table (Table1).
Either of the above procedures would do it for me.
Back to your reply, are you telling me that this is not a good design, would you please explain why?

Best regards
Bijan
0
 
LVL 77

Expert Comment

by:peter57r
ID: 12066768
So, as I understand it,  you have a bound form.
On the form you have a button which writes a record to a different table to the one the form is bound to - is that right?

You now want to save the the current record to its bound source and move to a new record- is that right?

If so then modify your code that writes to the second table to include:

Me.dirty = false
put this line before you write to the other table.
It will save the current record to the bound source.

After the code to write the other table put:
docmd.GoToRecord ,,acNewRec

This assumes that the code is in the form module and not in a standard module, otherwise you need
docmd.GoToRecord acDataForm,"formname",acNewRec.

Obviousy I do not know anything about your application, but itis unusual to add the same data to two different tables.
It is inevitable that at some point the tables get out of line, because of user actions or program bugs.

But you may have good reasons for doing this.

Pete
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:Bijanbijan
ID: 12072659
Hi Peter57r
I sort of figuredout the first part of the question, Could youb help me on secon part of the Question, I sort of figure that one also, I just have a little problem with it which I will present it to you.
I want to send some Data from an access Form to a SQL Database Table (not related Table)
I have the following Codes which Works:

Private Sub Command95_Click()
 Dim myCn As New ADODB.Connection
 Dim myRs As New ADODB.Recordset
  myCn.ConnectionString = "DSN=TestE"
 myCn.Open
 myRs.Open "INSERT INTO TABLE1  VALUES (" & OrderID.Value & "," & OrderID.Value + 10000 & ",'" & CustomerID.Value & "','" & CompanyName.Value & "','" & OrderDate.Value & "'," & Tax1.Value & "," & Tax2.Value & "," & Total.Value & ");", myCn, adOpenDynamic
 End Sub

But the Following Does not work:

Private Sub Command95_Click()
Dim myCn As New ADODB.Connection
 Dim myRs As New ADODB.Recordset
 myCn.ConnectionString = "DSN=TestE"
 myCn.Open
myRs.Open "INSERT INTO [dbo.OrderDetailsQoute] SELECT FROM [view.Order Details Extended] WHERE (OrderID=10036)", myCn, adOpenDynamic
 End Sub

Off Course the actual WHERE Condition is
WHERE (OrdrerID=Forms!Qoute!OrderID.Value)

Could some one tell me, why? (I think it should be in Punctuation Error in Insert Line.)

Best Regards
Bijan
0
 

Author Comment

by:Bijanbijan
ID: 12081702
Hi Peter
How are you?
I am stillw aiting for you reply on my last question.
Best Regards
Bijan
0
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 12086258
I guess you mean:
SELECT * FROM [view.Order Details Extended]

and to use a form reference you need:

 "INSERT INTO [dbo.OrderDetailsQoute] SELECT * FROM [view.Order Details Extended] WHERE (OrderID= " & Forms!Qoute!OrderID.Value & ")",

Pete
0
 

Author Comment

by:Bijanbijan
ID: 12102635
Hi Pete
I am sorry for delay.
But Thanks so much It worked just Fine.
Best regards
Bijan
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

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

Microsoft Jet database engine errors can crop up out of nowhere to disrupt the working of the Exchange server. Decoding why a particular error occurs goes a long way in determining the right solution for it.
Blockchain technology enhances society similar to the Internet. Its effects are broad, disruptive, and will boost global productivity.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

601 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