Solved

Message box Yes/No on Access 2010 subform

Posted on 2016-09-04
6
42 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 18

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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 18
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

705 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

18 Experts available now in Live!

Get 1:1 Help Now