Results 1 to 3 of 3
  1. #1
    raffie77 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    21

    Question VBA run sql criteria

    Hello people,

    I have a question


    I have a table with financial bank records
    I've made a query for example:
    filter all records where accountnummber = "000001" or 000002 or 0000003 or etc etc
    and I made a custom field called "type"
    if it matches one of those accountnumbers the type = "budget 1"
    it works fine,
    but I have like 10 queries and all those queries has lots of criteria s (or or or etc)
    is it possible to create a table where I put all query criteria s
    and do a docmd.runsql?
    I store the new transactions in a temporary table zo I can adjust the records and after that I merge the new records

    do I need to do something like?
    SELECT * from temptable where accountnumber =....
    do while loop look at the table or something?
    I want the criterias in a table and let vba look at that table and finish the SQL

    I hope I make sence


    Ralph

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Tried to replicate your problem. I have a very single Table with two Fields
    1) AccountNumber
    2) Type

    Objective:

    1) Want to assign value to field Type depending on the value of field Account Number.


    I have used a simple DAO.Recordset here with a combination of Do While Loop and a Select Case. All conditions are specified in the Select case which I have used to update the data in my table.

    Private Sub Command0_Click()
    Dim rst As DAO.Recordset


    Set rst = CurrentDb.OpenRecordset("Table1")
    Do While Not rst.EOF
    rst.Edit
    Select Case rst!AccountNumber
    Case Is = "0001"
    rst!Type = "Type1"
    Case Is = "0002"
    rst!Type = "Type2"
    Case Is = "0003"
    rst!Type = "Type3"
    Case Else
    rst!Type = ""
    End Select
    rst.Update
    rst.MoveNext
    Loop
    rst.Close
    Set rst = Nothing

    End Sub

    Mark the thread solved if your problem is solved.

  3. #3
    raffie77 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    21
    thanks a lot maximus

    I will take a look at that.
    at least I have a head start, I now know where to start.

    thanks a lot


    Ralph

Please reply to this thread with any new information or opinions.

Similar Threads

  1. criteria
    By kwooten in forum Queries
    Replies: 47
    Last Post: 08-03-2011, 09:12 AM
  2. Replies: 1
    Last Post: 07-13-2011, 11:00 AM
  3. Replies: 1
    Last Post: 06-12-2011, 07:08 AM
  4. Criteria help
    By jcaptchaos2 in forum Access
    Replies: 13
    Last Post: 05-08-2011, 06:49 PM
  5. Search By Criteria - Flexible Criteria Fields
    By lilanngel in forum Access
    Replies: 0
    Last Post: 03-16-2011, 06:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums