473,769 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL - INSERT INTO access2003

1 New Member
hello,

I'm trying to fill the table named "ALBARANES" which is based on a query. The query use table "structureO K". There are 3 additional values should be updated.

[date] AS Expr2
[Subject] AS Expr3
[Text] AS Expr1

I did this in access2003 and it works but each time I start the query I will be asked to enter a date, subject and text.

Now, I have created a form with textboxes, one for Date, one for Subject and one for text.

by starting the query instead of asking me to enter some values The query should take the data from the texboxes.
Therefore, as you can see below I defined 3 variables as string

str_text;
str_subject;
str_date

I getting in troulble if I try to change the SQL instrucction to include those variables.

Can someone help me out by this problem.
How I have to define the SQL to take the values from the variable?
below You have the code

thanks in advance

regards
logo3
-------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Dim objDB As DAO.Database
  2. Dim objRS As DAO.Recordset
  3. Dim strSQL As String
  4.  
  5. Dim str_text As String
  6. Dim str_subject As String
  7. Dim str_date As String
  8.  
  9.  
  10.  
  11.  
  12. str_text = gei_texto.Value ' to give the content of textbox (texto) to str_text
  13. str_subject = gei_asunto.Value ' to give the content of textbox (asunto) to str_subject
  14. str_date = gei_fecha.Value ' to give the content of textbox (fecha) to str_date
  15.  
  16. strSQL = "INSERT INTO ALBARANES ( [sales unit], unit, [jvperson], [jzperson], name, street, zipcode, city, city2, country, employee, phone, deliverydate, subject, Text ) SELECT structureOK.[sales unit], structureOK.unit, structureOK.[jvperson], structureOK.[jzperson], structureOK.name, structureOK.street, structureOK.[zipcode], structureOK.city, structureOK.[city2], structureOK.country, structureOK.customer, structureOK.[phone 1], [date] AS Expr2, [subject] AS Expr3, [Text] AS Expr1  FROM structureOK WHERE (((structureOK.unit)='18-000'));"
  17.  
  18.  
  19.  
  20. Set objDB = CurrentDb
  21.  
  22. Set objRS = objDB.OpenRecordset(strSQL, , DAO.dbSQLPassThrough)
  23.  
  24.  
  25. Call objRS.Close
  26. Set objRS = Nothing
  27.  
  28. Set objDB = Nothing
-------------------------------------------------------------------------
Nov 27 '07 #1
2 9596
NeoPa
32,573 Recognized Expert Moderator MVP
I'm afraid you've made this harder than it needs to be, but I expect that's because there are bits you don't understand too well. Not a problem.
There are two ways to do this & I will doctor your code to show my preferred way (inserting the values from the form directly into your SQL string as literal values).
Expand|Select|Wrap|Line Numbers
  1. Private sub Blah_blah_blah()
  2.   Dim objDB As DAO.Database
  3.   Dim objRS As DAO.Recordset
  4.   Dim strSQL As String
  5.  
  6.   strSQL = "INSERT INTO ALBARANES (" & _
  7.            "[sales unit], unit, [jvperson], [jzperson], name, " & _
  8.            "street, zipcode, city, city2, country, employee, " & _
  9.            "phone, deliverydate, subject, Text) " & _
  10.            "SELECT [sales unit], unit, [jvperson], [jzperson], " & _
  11.            "[name], [street], [zipcode], [city], [city2], " & _
  12.            "country, customer, [phone 1], " & _
  13.            Format(Me.gei_fecha,'\#m/d/yyyy\#') & ", " & _
  14.            "'" & Me.gei_asunto & "', " & _
  15.            "'" & Me.gei_texto & "' " & _
  16.            "FROM structureOK " & _
  17.            "WHERE ([unit]='18-000')"
  18.   Set objDB = CurrentDb
  19.   Set objRS = objDB.OpenRecordset(strSQL, , DAO.dbSQLPassThrough)
  20.   Call objRS.Close
  21.   Set objRS = Nothing
  22.   Set objDB = Nothing
  23. End Sub
Nov 28 '07 #2
NeoPa
32,573 Recognized Expert Moderator MVP
Remember, the SQL command is simply stored in a string. You prepare the string in advance and if you think of the resultant SQL code as data rather than as part of the coding, it's easier to understand and avoid confusion.
Nov 28 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1531
by: Dennis | last post by:
If I create a database in AccessXP-2000mode, can someone with Access2003 run it? Do either of us have to do anything special? Thanks! Dennis
9
2417
by: Lauren Quantrell | last post by:
Hoping someonce can tell me what compatibility problems I might run into when I have to have my Access Project developed on Access2K run in a user environment where users are using Access2003 as well as Access2000. I have already seen a problem where if I open my project using Access2003 and save any objects, then run it on Access2000, I encounter "Bad DLL Calling Convention error..." on the Access2K machines. If I never open and save the...
6
2010
by: Ryan Bounds | last post by:
Hi All We have upgraded from Access2000 to Access2003 with all service packs. The problem that we have is: When a user try's to filter a client the database crashes and close's Access2003, this is happening on a regular basis. We never had this problem in Access2000. Would it be something to do with code?
9
1904
by: Zlatko Matiæ | last post by:
Hello. Could somebody explain the following situation: I have a .mdb on my notebook with Windows XP SP2 and Access 2003. I prepared ..mde and tried to use it on another computer with Windows XP SP2 and Office XP installed on it. An error "...Your VBA project is corrupted" appeared. When I copy .mdb to that computer, instead of .mde, it works. If I then make the .mde on that computer, it works! If I copy the .mde then to the first...
9
2943
by: 2D Rick | last post by:
With the help from members in the VB forum I've pieced together code that works in VB6 to create radial text similar to "text on a path" seen in graphics programs.(on a circle only) I use an Access2003 app to gather the data via a barcode reader which is then concatenated for the radial text. Is there any possibility that this code can be converted to run in Access2003? Option Explicit
3
1711
by: Vera | last post by:
I built a class in VB.NET that has an overloaded constructor. It can either accept nothing, a string or an object Public Sub New( MyBase.New( End Su Public Sub New(ByVal strName As String MyBase.New( '... Do init with strNam End Su
13
3034
by: usenet | last post by:
How and where can one find out about the basics of VB/Access2003 syntax? I am a died in the wool C/C++/Java Linux/Unix programmer and I am finding it difficult to understand the program format for accessing objects, controls, etc. in VB/Access2003. In particular where will I find explanations of:- Actions, Functions, Methods, Properties - I'm understand the
3
3711
by: emlimeng | last post by:
hi everyone, I need help on an error message. I am working on an environment that Access2003 (adp) as a front end and links to SQL server as a back end. I am creating a table, which requests users insert a value(varchar) into the table throuth an input box on a form. Please see the code is below: Public Sub cmdAdd_Click() Dim cmd As ADODB.Command Set cmd = New ADODB.Command Dim getStrUR As String ...
3
1960
by: Ramchandar | last post by:
Hi, I am creating reports using VBA code. I have the same query in a querydef residing both in Access97 and Access2003. The result of this querydef is then moved to a table in Access97 and Access2003 respectively. The table in Access97 returns 874 rowcount, table in Access 2003 returns 1050 rowcount. In both the case the querydef is retrieving from the same database which resides in SQL Server 2003. I executed the application Access97 and...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9857
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7404
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.