Code Help

StacyStacy

A "Californian" at heart!
Local time
Today, 12:52
Joined
Jan 29, 2003
Messages
159
Hi. Can someone help me write the following code that works in FoxPro for Access:

FINDME="42002"
SELECT *;
FROM uidata;
WHERE ex1quart + EX1YEAR = FINDME ;
OR ex2quart + ex2year = FINDME ;
OR ex3quart + ex3year = FINDME ;
OR ex4quart + ex4year = FINDME ;
OR ex5quart + ex5year = FINDME ;
OR pr3quart + pr3year = findme ;
or pr2quart + pr2year = findme ;
or pr3qdisl + pr3ydisl = findme ;
or pr2qdisl + pr2ydisl = findme ;
into table Q4Yr2002

select q4yr2002
go top
copy to q4yr2002.txt type sdf fields ssn

I want to create a varible whereby the user will have to enter the "Findme" - '42002'.

Thanks!
 
My FoxPro is a little rusty, but this may help.

Code:
Public Function Exportuidata()
    Dim rst As New ADODB.Recordset
    Dim conn As New ADODB.Connection
    Dim sSQL As String
    Dim iFile As Integer
    Dim FINDME As String
    
    'Parameter using an InputBox
    FINDME = InputBox("Format (QYYYY)", "Find Me", "42002")
    
    'This is the SQL String for the Recordset object
    sSQL = "Select * From uidata Where (ex1quart & EX1YEAR = '" & FINDME & "' ) " & _
                                   "OR (ex2quart & ex2year = '" & FINDME & "' ) " & _
                                   "OR (ex3quart & ex3year = '" & FINDME & "' ) " & _
                                   "OR (ex4quart & ex4year = '" & FINDME & "' ) " & _
                                   "OR (ex5quart & ex5year = '" & FINDME & "' ) " & _
                                   "OR (pr3quart & pr3year = '" & FINDME & "' ) " & _
                                   "OR (pr2quart & pr2year = '" & FINDME & "' ) " & _
                                   "OR (pr3qdisl & pr3ydisl = '" & FINDME & "' ) " & _
                                   "OR (pr2qdisl & pr2ydisl = '" & FINDME & "' ) "
    'Open the Recordset
    Set conn = CurrentProject.Connection
    rst.Open sSQL, conn, adOpenStatic, adLockReadOnly
    
    On Error Resume Next
    rst.MoveFirst
    'If there is an error exit
    If Err <> 0 Then Exit Function
    'If there are no records exit
    If rst.EOF Then Exit Function
    
    
    'Open the q4yr2002.txt document in the current path
    iFile = FreeFile
    Open CurrentProject.Path & "\q4yr2002.txt" For Output As iFile
    
    'Loop through the records and writing them to the file
    Do While Not rst.EOF
        'Print the ssn field
        Print iFile, rst!ssn
        'Move to the next record
        rst.MoveNext
    Loop
    
    'Close the file
    Close iFile
    rst.Close
    conn.Close
    

End Function
 
Thank you! I will try this and let you know how it turns out. ;)
 

Users who are viewing this thread

Back
Top Bottom