473,795 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieving Data from a Form

13 New Member
Hi, this is my first attempt to create variables to assign a value, so thanks for any suggestions.

I have a field in a form I'd like to match a substring of to another table and insert. The problem is in retrieving the value. It pops a window where if I put in the AcctNumb value it works, but this is obviously not right. My code is:

Private Sub FinishBtn_Click ()

Dim AcctSysprin As String
AcctSysprin = "Forms![FrmEsc4Disp]![AcctNumb].Value"
AcctSysprin = Left(AcctSyspri n, 8)

Dim AcctCitySQL As String
AcctCitySQL = "INSERT INTO TblDateContact"
AcctCitySQL = AcctCitySQL + " (FldCity)"
AcctCitySQL = AcctCitySQL + " SELECT FldMarket"
AcctCitySQL = AcctCitySQL + " FROM TblMarket"
AcctCitySQL = AcctCitySQL + " WHERE FldSysprin = AcctSysprin"

DoCmd.SetWarnin gs True
DoCmd.RunSQL AcctCitySQL
DoCmd.Save
DoCmd.GoToRecor d , , acNewRec
End Sub
Jun 16 '07 #1
6 1935
ADezii
8,834 Recognized Expert Expert
Hi, this is my first attempt to create variables to assign a value, so thanks for any suggestions.

I have a field in a form I'd like to match a substring of to another table and insert. The problem is in retrieving the value. It pops a window where if I put in the AcctNumb value it works, but this is obviously not right. My code is:

Private Sub FinishBtn_Click ()

Dim AcctSysprin As String
AcctSysprin = "Forms![FrmEsc4Disp]![AcctNumb].Value"
AcctSysprin = Left(AcctSyspri n, 8)

Dim AcctCitySQL As String
AcctCitySQL = "INSERT INTO TblDateContact"
AcctCitySQL = AcctCitySQL + " (FldCity)"
AcctCitySQL = AcctCitySQL + " SELECT FldMarket"
AcctCitySQL = AcctCitySQL + " FROM TblMarket"
AcctCitySQL = AcctCitySQL + " WHERE FldSysprin = AcctSysprin"

DoCmd.SetWarnin gs True
DoCmd.RunSQL AcctCitySQL
DoCmd.Save
DoCmd.GoToRecor d , , acNewRec
End Sub
Try:
Expand|Select|Wrap|Line Numbers
  1. Private Sub FinishBtn_Click()
  2. Dim AcctSysprin As String
  3. AcctSysprin = Forms![FrmEsc4Disp]![AcctNumb]
  4. AcctSysprin = Left$(AcctSysprin, 8)
  5.  
  6. Dim AcctCitySQL As String
  7. AcctCitySQL = "INSERT INTO TblDateContact"
  8. AcctCitySQL = AcctCitySQL & " (FldCity)"
  9. AcctCitySQL = AcctCitySQL & " SELECT FldMarket"
  10. AcctCitySQL = AcctCitySQL & " FROM TblMarket"
  11. AcctCitySQL = AcctCitySQL & " WHERE FldSysprin = '" & AcctSysprin & "'"
  12.  
  13. DoCmd.SetWarnings True
  14. DoCmd.RunSQL AcctCitySQL
  15. DoCmd.Save
  16. DoCmd.GoToRecord , , acNewRec
  17. End Sub
Jun 16 '07 #2
ReubenPatterson
13 New Member
Thanks! I'm getting a Data Type Mismatch error...?

Try:
Expand|Select|Wrap|Line Numbers
  1. Private Sub FinishBtn_Click()
  2. Dim AcctSysprin As String
  3. AcctSysprin = Forms![FrmEsc4Disp]![AcctNumb]
  4. AcctSysprin = Left$(AcctSysprin, 8)
  5.  
  6. Dim AcctCitySQL As String
  7. AcctCitySQL = "INSERT INTO TblDateContact"
  8. AcctCitySQL = AcctCitySQL & " (FldCity)"
  9. AcctCitySQL = AcctCitySQL & " SELECT FldMarket"
  10. AcctCitySQL = AcctCitySQL & " FROM TblMarket"
  11. AcctCitySQL = AcctCitySQL & " WHERE FldSysprin = '" & AcctSysprin & "'"
  12.  
  13. DoCmd.SetWarnings True
  14. DoCmd.RunSQL AcctCitySQL
  15. DoCmd.Save
  16. DoCmd.GoToRecord , , acNewRec
  17. End Sub
Jun 16 '07 #3
ReubenPatterson
13 New Member
Thanks! I'm getting a Data Type Mismatch error...?
OK, I've corrected the table data type, but still getting " Syntax Error (Missing Operator) in query expression 'FldSysprin=' "

Any Ideas? Thanks again for your help.
Jun 16 '07 #4
ADezii
8,834 Recognized Expert Expert
OK, I've corrected the table data type, but still getting " Syntax Error (Missing Operator) in query expression 'FldSysprin=' "

Any Ideas? Thanks again for your help.
Change Line #11 in Post #3 to:
Expand|Select|Wrap|Line Numbers
  1. 'Syntax is different since value is Numeric
  2. AcctCitySQL = AcctCitySQL & " WHERE FldSysprin = " & AcctSysprin   
  3.  
Jun 16 '07 #5
ReubenPatterson
13 New Member
Progress! Runs without errors, but says "Updating 0 rows" and nothing populates...I appreciate the suggestions.
Jun 16 '07 #6
ADezii
8,834 Recognized Expert Expert
Progress! Runs without errors, but says "Updating 0 rows" and nothing populates...I appreciate the suggestions.
That's because
Expand|Select|Wrap|Line Numbers
  1. "SELECT FldMarket FROM TblMarket WHERE FldSysprin = " & AcctSysprin
returns no Records.
Jun 16 '07 #7

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

Similar topics

0
1586
by: Alistair | last post by:
Hi all, I am creating a database based site that keeps track of books, who has read them and the comments they have. After a little help in M.P.I.asp.DB I managed to create a database (access 2000) as follows USERS TABLE
6
9655
by: Dave Hopper | last post by:
Hi I am using the following SQL to retrieve a value in a list box using a unique ID held in the list box call cntID. The list box is used on an order form to list appointments that have been made for service staff. My problem is the SQL is not retrieving the value of the listbox. I have tested the SQL by entering a fixed value of a valid entry in the listbox and it works fine, but as soon as I replace the fixed value with...
5
2237
by: aniket_sp | last post by:
i am using a data adapter and a dataset for filling and retrieving data into .mdb database. following is the code..... for the form load event Dim dc(0) As DataColumn Try If OleDbConnection1.State = ConnectionState.Closed Then OleDbConnection1.Open() Else
7
2060
by: Sirplaya | last post by:
I am retrieving images that I stored in SQL Server on my web pages in C#. I have no problem with the images displaying, however, I am trying to wrap the image with an <A HREF ..." and each time I try, it acts like the link is not even on the image. What is the proper way to do this? Thanks.
1
9450
by: jimmyfo | last post by:
Hi, I recently wrote an ASP.Net web application in VS2005 and published (using VS2005 Publish feature) it to a relatively clean machine with ASP.Net 2.0 and MDAC 2.8 installed on it. However, when I try to create my SQL connection in the code-behind, I get the following error. I tried to register the DLL using regsvr32 but that errored out saying, "dllregisterserver entry point was not found". Any ideas? Retrieving the COM class factory...
2
2008
by: 4Ankit | last post by:
hello all, i am having some difficulty retrieving information from my form. I want to add content in my table but the content i want to add to the table is what the user inputs in my form. Basically i want to know how i retrieve information from the form so i can disaply it in the table. i have put the code i am using below, the feature i cannot get to work is the change content function. I want the email address entered by the...
5
1981
by: Sanjay Pais | last post by:
I have a table with over 1.3 million rows. I am retrieving only 20 at a time using the with - over clauses In query analyser, the data is retrieved in under a second. When retrieving using the data adaptor.fill or datareader to retrieve the data it takes over 24 seconds. public System.Data.SqlClient.SqlDataReader List1(int PageIndex, int PageSize, string ItemName, string UserIDs, DateTime DateStart, DateTime DateEnd, int status,...
0
3398
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options within options. I have everything being dynamically named from the previously dynamically named element. (I hope this makes sense.) I am not able to retrieve any of the dynamically created values. I can view them on the source page but can't pull them...
1
2441
by: san123456789 | last post by:
Hi, Im using a MS SQL server to store images... Im creating a windows form application using C#. I need to store and retrieve images from the database. This is my code to store images: pictureBox.Image = new System.Drawing.Bitmap(this.openFileDialog.FileName);
34
2585
by: vpriya6 | last post by:
Hi guys, I am new to Ajax, xml and javascript. I want to know how can I retrieve data from xml and display in the html page? please help me out. suppose my xml file is customer.xml the code is below: <CUSTOMER>
0
9673
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
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
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
5440
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
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2922
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.