Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Message box Yes/No on Access 2010 subform

Posted on 2016-09-04
6
Medium Priority
?
68 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 23

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 2000 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

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

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

Expert Comment

by:Dale Fye
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

926 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