473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Changing SQL to VB code for use in MSA

12
I have no clue how to write in code but my Access program needs demand that I use code to validate a field. Somewhere I read you can copy an Access query's SQL code into VB code and only need to modify the controls that have user defined parameters.

I already have a query built that generates this SQL:

SELECT [T - Main Frame].[MSO #], [T - Main Frame].[Part #], Sum([T - Main Frame].Quantity) AS SumOfQuantity
FROM [T - Main Frame]
WHERE ((([T - Main Frame].Status)="Received" Or ([T - Main Frame].Status)="Shipped" Or ([T - Main Frame].Status)="Scrapped"))
GROUP BY [T - Main Frame].[MSO #], [T - Main Frame].[Part #]
HAVING ((([T - Main Frame].[MSO #])=136556) AND (([T - Main Frame].[Part #])="10R2538"));

I think I have to change the "136556" to "Forms!Shipping!Combo3", and "10R2538" to "Forms!Shipping!Combo8" which are the values in a set of combo boxes on my form.

Here is the code in VB that I have to do this "inline". The "strSQL" in the IF statement is the above SQL.

Private Sub Quantity_AfterUpdate()
If Quantity > strSQL Then
MsgBox "Insufficient quantity available for current MSO #", vbOKOnly
Me!Control = Null
Me!Control.SetFocus
End If
End Sub

Basically I don't know how to structure the SQL in code so that it performs the same action as the query. Any input would be helpful.

If anyone knows where I can get a quick reference to the format for building these types of statements in code I could pick it up myself.

Obviously I should take a class for this, but hopefully someone has the time to help while I schedule that class for next trimester. Today marks day 3 of my attempt at getting this to work.

If I should post in a different forum please feel free to tell me so.
Sep 16 '08 #1
6 1002
debasisdas
8,127 Expert 4TB
i dont understand what is the use of the following line in your code

If Quantity > strSQL Then
Sep 16 '08 #2
glitke
12
i dont understand what is the use of the following line in your code

If Quantity > strSQL Then
This line checks to see if the value that a user inputed is > the available quantity to be shipped.

So the "Quantity" is what the user inputted.

The "strSQL" is actually a query that finds the max quantity available.

The way the "available quantity to be shipped" is calculated is by
1. - selecting all records on the table, T - Main Frame,
- where the records status is either "Shipped", "Scrapped", or "Received",
and
- where the MSO# of that record matches what the user selected from a
ComboBox on the same form, Combo3, and
- where the Part # of that record matches what ther user selected from a
ComboBox on the same form, Combo8.

2. - Then the sum of the field "Quantity" of the records selected is taken and
produces a single number, the "max quantity available".

I hope that explains it. If it still doesn't make sense don't worry about it. I'll hammer my way through it in time.
Sep 16 '08 #3
debasisdas
8,127 Expert 4TB
you can't compare two strings like that using > operator.
Sep 16 '08 #4
glitke
12
you can't compare two strings like that using > operator.

Ok. Thanks for the info.
Sep 17 '08 #5
glitke
12
you can't compare two strings like that using > operator.
So how do you compare two strings in code then?
Sep 17 '08 #6
glitke
12
So how do you compare two strings in code then?
Here's what I've come up with. And this code goes under "Event - Lost Focus" for the control "Quantity" on Form "Shipping".

Private Sub Quantity_LostFocus()

If (StrComp("[Quantity]", "[Q - Limit Quantities]![Sum Of Quantity]", vbBinaryCompare)) = 1 Then
MsgBox "Insufficient Quantity", vbOKOnly
End If

End Sub

Another note, the value of the "Sum Of Quantity" from SQL "[Q - Limit Quantities]![Sum Of Quantity]", is from a Query that uses the values in two ComboBoxes on the form that I'm using this code.
Sep 17 '08 #7

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

Similar topics

0
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
2
by: Urs Vogel | last post by:
Hi When using XmlDocument, I can create nodes and attributes as I like. What I didn't achieve is changing the Value of a node (created with createElement), it claims that it's the wrong node...
3
by: Michael | last post by:
Hi everyone, I am trying to change the field names for a table that is being exported via Excel. Its a spreadsheet that our National Office sends us but even after promise after promise they...
7
by: Dan Sikorsky | last post by:
How do you iterate thru a dataset to change money fields to a different value? Here's what I have. My dataset is filled directly from a stored procedure. ' Create Instance of Connection and...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
32
by: deko | last post by:
I have a popup form with a textbox that is bound to a memo field. I've been warned about memo fields so I'm wondering if I should use this code. Is there any risk with changing the form's...
12
by: GaryDean | last post by:
In the original post I failed so indicate that I am using framework 1.1....... I need to be able to change the background color of a page from code. I found an answer to this question in...
18
by: Chris Hills | last post by:
A lesson in Posting How many C.L.C group posters does it take to change a C light bulb? 1 to change the light bulb and to post that the light bulb has been changed 14 to share similar...
17
by: blufox | last post by:
Hi All, Can i change the execution path of methods in my process at runtime? e.g a()->b()->c()->d()->e() Now, i want execution to be altered at runtime as -
3
by: Darkside12 | last post by:
Hi, I'm trying to build a dynamic query by form. The idea is that a user can select a table in the database via a combo box and this will then change all of the text box labels on the form to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.