Solved

Message box Yes/No on Access 2010 subform

Posted on 2016-09-04
6
58 Views
Last Modified: 2016-09-05
I have a main form & subform. The subform displays item data info with different prices ( ItemID, ItemCode, Price1,Price2, Price3) . When the user clicks on a field (say Price1) all relevant fields are assigned to variables for later processing. I have a yes/no message box pop up confirming the selected fields of the record.  All variables shown in the message have the correct values. What I want to do is, when the answer is yes, to insert the variables into a table. However, nothing happens when the answer is yes. The DoCmd.RunSQL  assigned does not fire off . Any help is appreciated.
0
Comment
Question by:thao-nhi
[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
  • 3
  • 2
6 Comments
 
LVL 20

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 500 total points
ID: 41784032
if the record is being edited then it is generally better for the code to write to controls provided the values are in them.  
me.controlname = value

Open in new window


Is this a bound form?
If yes and you do want to change values in the record being edited using SQL, be sure to first save the record
if me.dirty = true then me.dirty = false

Open in new window

Is there a reason you are using DoCmd.TunSql instead of CurrentDb.Execute? What is an SQL statement that is not executing?

why do you have so many prices in one record? Perhaps the data structure could use some help too?
0
 

Author Comment

by:thao-nhi
ID: 41784095
The subform is bound to a table1  to show the data. When clicked, the record data will be inserted into table2. 1 record is for 1 item & 1 Item has different prices like wholesale, retail &  bulk.

So far I got:

Click_Event

Dim LResponse As Integer
Dim CustID as String
Dim sqls As String

LResponse = MsgBox("You selected" & vbCrLf & ItemCode & vbCrLf & "$" & ItemPrice & vbCrLf _
& "for W/O:" & " " & TempVars!CurrentWO_ID.Value & vbCrLf & "Please confirm!", vbYesNo, "Adding Item To Quotation")


If LResponse = vbYes Then
CustID = left(TempVars!CurrentWO_ID.Value,8)
sqls = "insert into Quotation (CustomerID, Item_Code, Item_Price) values('" & CustID & "', '" & ItemCode & "', '" & ItemPrice & "');"
DoCmd.RunSQL sqls

End If
0
 

Author Closing Comment

by:thao-nhi
ID: 41784114
thanks
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 20
ID: 41784178
you're welcome ~ happy to help

 ... did you get it working?
1
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 41784569
thao-nhi,

When you write your SQL statement, you must wrap text strings with single or double quotes, but numeric values should not have those.  It appears that your SQL string contains several of these characters which it should not.  Assuming that CustomerID and Item_Price are numeric values and that Item_Code is a string, the SQL would look like:

sqls = "insert into Quotation (CustomerID, Item_Code, Item_Price) " _
        & "values(" & CustID & ", '" & ItemCode & "', " & ItemPrice & ");"

HTH
Dale
0
 

Author Comment

by:thao-nhi
ID: 41784738
Thanks for the note. I'll correct that
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

710 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