Results 1 to 4 of 4
  1. #1
    Dengkee is offline Novice
    Windows 7 Access 2002
    Join Date
    May 2010
    Posts
    4

    Sql in vba

    hello ppl,



    i have table "RATE" that contains fields "ENO, GRADEC, RATEC" now i would like to write a SQL statement that returns RATEC after i supplied the data on ENO and GRADEC. Can an1 help me please?

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Where is ENO and GRADEC being pulled from? I'll assume from a form and answer as if thats true. Let me know otherwise. Lets assume they are textboxes (they can be whatever) called txtENO and txtGRADEC respectively.

    dim strSQL As String

    strSQL = "SELECT RATEC FROM RATE WHERE ENO = " & me.txtENO & " AND GRADEC = " & Me.txtGRADEC & ";"

    docmd.RunSql (strSQL)

  3. #3
    Dengkee is offline Novice
    Windows 7 Access 2002
    Join Date
    May 2010
    Posts
    4
    ENO and GRADEC is a return value from a function. i tried to call the function from the sql statement you gave me but im sure if this is how to do it. Heres my code below.

    Public Function LOADRATE() As String
    Dim strSQL As String
    strSQL = "SELECT RATEC FROM RATE WHERE ENO = " & LOADENO & " AND GRADEC = " & LOADGRADE & ";"
    DoCmd.RunSQL (strSQL)
    End Function

    Public Function LOADENO() As String
    Dim ENOC As String
    ENOC = DLookup("ENO", "QUOTE")
    End Function

    Public Function LOADGRADE() As String
    Dim IMIX As Variant
    IMIX = CMTC + SCSCDC + SCDC + DSCTC + WSCTC + MSC + PFAC + CIC + WPC + FBC + SCCC + ICEC + PUMPC
    GR = GRADE
    Select Case GR
    Case "PMPMOB"
    Forms!REQUISITION!GRADEC = "PUMP MOBILIZATION"
    Case "TCHARGE"
    Forms!REQUISITION!GRADEC = "TRANSPORT CHARGE"
    Case "GROUT"
    Forms!REQUISITION!GRADEC = GRADE + IMIX
    Case "MORTAR"
    Forms!REQUISITION!GRADEC = GRADE + IMIX
    Case Else
    Forms!REQUISITION!GRADEC = "B" + GRADE + "-G" + IMIX
    End Select

    Forms!REQUISITION!RATE.Requery
    End Function

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    make them public variables. then whatever they are set to in other functions will be able to be passed into that one.

    Public ENO As whateverdatatype
    Public GRADEC As whateverdatatype

    public function whatever()
    blah blah blah
    assigns values to ENO and GRADEC
    end function

    Public Function LOADRATE() As String
    Dim strSQL As String
    strSQL = "SELECT RATEC FROM RATE WHERE ENO = " & LOADENO & " AND GRADEC = " & LOADGRADE & ";"
    DoCmd.RunSQL (strSQL)
    End Function

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

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