Pull info from two tables and and a query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jollywg
    New Member
    • Mar 2008
    • 158

    #1

    Pull info from two tables and and a query

    I've got two tables tblPatient and tblIV. I have the PatientWeight in tblPatient, PatientAge in qryCalcPatientA ge, and IJEE in tblIV. What i am needing to do is get the weight and age from the table and multiply them together to get the IJEE. I'm using VBA is it possible?!? if not how would I go about doing this?
    Thanks for input

    Matt
  • PianoMan64
    Recognized Expert Contributor
    • Jan 2008
    • 374

    #2
    Originally posted by Jollywg
    I've got two tables tblPatient and tblIV. I have the PatientWeight in tblPatient, PatientAge in qryCalcPatientA ge, and IJEE in tblIV. What i am needing to do is get the weight and age from the table and multiply them together to get the IJEE. I'm using VBA is it possible?!? if not how would I go about doing this?
    Thanks for input

    Matt
    The easist way to deal with that is to make it part of the query. When you create your select statement, you include your equations along with it.

    I can get any more detail of an answer without having table structure and fields listed out.

    Hope that help,

    Joe P.

    Comment

    • Jollywg
      New Member
      • Mar 2008
      • 158

      #3
      Joe thanks for the reply,
      tblPatient and tblIV are joined by PatientID key. qryPatientAge is joined to tblPatient with PatientID as well. How would I go about writing sql for that query here is what i tried, but it kept giving me errors. (tblIV.Trauma is a checkbox on a form)
      [CODE=SQL]SELECT tblIV.Vent, tblPatient.Gend er, tblPatient.[WeightKG], tblIV.Trauma, qryFindAge.Pati entAge,

      (If (tblIV.Trauma = true) THEN INSERT INTO tblIV.IJEE (tblPatient.Wei ght * qryFindAge.Pati entAge)) END IF

      FROM (tblPatient INNER JOIN tblIV ON tblPatient.Pati entID=tblIV.Pat ientID)
      INNER JOIN qryFindAge ON tblPatient.Pati entID=qryFindAg e.PatientID;[/CODE]
      Again thanks for the help
      Last edited by NeoPa; Apr 30 '08, 12:50 PM. Reason: Added [CODE] tags - Please remember in future

      Comment

      • PianoMan64
        Recognized Expert Contributor
        • Jan 2008
        • 374

        #4
        Originally posted by Jollywg
        Joe thanks for the reply,
        tblPatient and tblIV are joined by PatientID key. qryPatientAge is joined to tblPatient with PatientID as well. How would I go about writing sql for that query here is what i tried, but it kept giving me errors. (tblIV.Trauma is a checkbox on a form)

        SELECT tblIV.Vent, tblPatient.Gend er, tblPatient.[WeightKG], tblIV.Trauma, qryFindAge.Pati entAge,

        (If (tblIV.Trauma = true) THEN INSERT INTO tblIV.IJEE (tblPatient.Wei ght * qryFindAge.Pati entAge)) END IF

        FROM (tblPatient INNER JOIN tblIV ON tblPatient.Pati entID=tblIV.Pat ientID)
        INNER JOIN qryFindAge ON tblPatient.Pati entID=qryFindAg e.PatientID;

        Again thanks for the help
        Well Jollywg,

        The reason it is not working at all is your syntax for a select statement is wrong. The second thing that you need to understand is that don't get in a habit of storing calculated field into another table, because the problem comes in when you change the values. Then you have a problem.

        For example:

        Code:
        SELECT tblIV.Vent, tblPatient.Gender, tblPatient.[WeightKG], tblIV.Trauma, qryFindAge.PatientAge, IJEE:=IIF([tblIV.Trauma],tblPatient.Weight * qryFindAge.PatientAge,0)
        FROM (tblPatient INNER JOIN tblIV ON tblPatient.PatientID=tblIV.PatientID) 
        INNER JOIN qryFindAge ON tblPatient.PatientID=qryFindAge.PatientID

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          Originally posted by Jollywg
          ...(tblIV.Traum a is a checkbox on a form)..
          This is going to sound argumentative, but "No it isn't!"
          tblIV.Trauma must be a field in a table ([tblIV]). It is possible that you have a separate control on a form bound to this value. It's even possible it's called [Trauma]. Not tblIV.Trauma though.

          Why don't you post your table meta-data for us and try to explain more clearly what you're after. Maybe we can help some more in those circumstances. This will work much better if you can post the meta-data (info about the layout / structure) of the table in the same way as I use in my example. Click on the Reply button and you will have access to all the codes I've used.
          Code:
          Table Name=[[U]tblStudent[/U]]
          [I]Field; Type; IndexInfo[/I]
          StudentID; AutoNumber; PK
          Family; String; FK
          Name; String
          University; String; FK
          Mark; Numeric
          LastAttendance; Date/Time

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            I'm afraid this question was double-posted by the OP and the other thread (Tables VBA Code) had a helpful answer in it. Chronology would have been very confusing had the threads simply been merged.

            Comment

            Working...