Solved

Message box Yes/No on Access 2010 subform

Posted on 2016-09-04
6
47 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
  • 3
  • 2
6 Comments
 
LVL 19

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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

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

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

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now