Results 1 to 5 of 5
  1. #1
    JST2017 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2017
    Posts
    3

    Query based on three variables

    Hello Accessforums users,

    I am relatively new to MS Access, and I am looking for best practices so I don't for any bad habits.

    Currently I am looking open a form from a query based on three variables that can potentially result in no values. Which brings me to my two questions.

    1). What is the best way to handle the situation in which no value is returned? I would ideally like to open a form to a new record with the variables they selected on the form.

    2). My table records are based on the three variables. If they match, meaning there is a record available, I would like to "Up rev" the previous record. Essentially copying the previous records fields increasing the revision level.



    Example of the table:

    RecordID Variable1 Variable2 Variable3 Revision Value1 Value2 Value3
    1 x y z 1 1 12 13
    2 x y z 2

    Continuing question #2...
    So I would input my variables: x,y,z. This would match the previous revision, so I would get a "match", copy record 1, and up rev. So my form would show me the values and allow me to edit, but I do not want to be able to edit revision 1, so I create a copy and up rev it.

    I am sorry if this doesn't make sense, but I do not have enough access knowledge yet to put it in better terms...

    Thank you in advance for any help!

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Your query should show records,if any.
    if not, open the form to add. (Using a Find button)

    Code:
    Sub btnFind_click()
    Dim lCount as long
    
    lCount= Dcount("*","qsFindQry")
    if lCount=0 then
        Docmd.openForm "frmExistingRecs", ,,,acFormAdd.         'Add new
    else
        Docmd.openForm "frmExistingRecs"     'Continuous form using qsFindQry
    end if
    end sub

  3. #3
    JST2017 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2017
    Posts
    3
    ranman,

    Thank you that works perfectly.

    In regards to the populating the form with the variables, how can I pass those variables?

  4. #4
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    What variables?
    if the form is open,you can access the objects.
    you can pass vars to a subroutine with arguments.

    Usage:
    GetMyDAta 21,"bob"

    Code:
    Sub GetMyData ( pvNum, pvName)
      MsgBox pvName,,pvNum
    
    end sub

  5. #5
    JST2017 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2017
    Posts
    3


    That is the closest thing I could find to a facepalm. Thank you ranman!

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

Similar Threads

  1. Variables in query field
    By saechaoc in forum Access
    Replies: 3
    Last Post: 09-22-2015, 02:47 PM
  2. Replies: 3
    Last Post: 02-06-2014, 10:17 AM
  3. Replies: 8
    Last Post: 09-19-2013, 06:22 AM
  4. Replies: 7
    Last Post: 03-14-2012, 10:56 AM
  5. Append Query using variables
    By hawg1 in forum Queries
    Replies: 2
    Last Post: 06-09-2010, 08:59 AM

Tags for this Thread

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