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.