very basic, basic ;)

kicken18

Registered User.
Local time
Today, 18:52
Joined
Oct 19, 2004
Messages
22
in VBA, i want to write something along the lines of
Code:
if Customer Name = Orders > 5
PromptBox "sorry only 5 orders max"
do i just use the varible names like in SQL like TBL_Customer.CustomerID
or is it differnt for VBA

Thanks
Chris
 
Are you wanting to display a msgbox if a customers total orders are >5?
 
yes, but thats not the question here, my question is i am trying to write something which looks at a customer ID and if they have > 5 order ID's (they have over 5 orders) then a message box comes up. Now in SQL its TBL_Customers.CustomerID do i write the same in VBA?
 
if you already have a query, you can just call they query by it's name, otherwise:

Option (1)
Code:
Dim strSQL As String
Dim rs as Recordset

strSQL = "SELECT [ORDERS] FROM [TABLENAME] WHERE [CUSTOMER NAME] = 'John';"

Set rs = CurrentDb.OpenRecordset(strSQL)
rs.MoveLast

If Not (rs.BOF And rs.EOF) Then
    rs.MoveFirst
    If (rs.RecordCount > 5) Then
        Msgbox "Sorry 'customer name' you may have a maximum of 5 orders at a given time"
    End If
End If


Option (2):
Code:
Dim intCount As Integer

intCount = DCount("[ORDERS]","Table Name","[CUSTOMER NAME] = 'John' ")

If intCount > 5 Then
    Msgbox "Sorry 'customer name' you may have a maximum of 5 orders at a given time"
End If

Note: In both cases you can replace [ORDERS] with * because I'm assuming a records is entered for each order a customer places.

Hope this helps
 
Last edited:
Are you entering the orders via a form, if so the RecordsetClone.RecordCount method will work
 

Users who are viewing this thread

Back
Top Bottom