Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in code.

Status
Not open for further replies.

Jahappz

Technical User
Jun 3, 2002
133
SE
Hello!

I have the following VBA code in my Access database, but it keeps complaining on the line: Dim DBS As Database
Any one knows whats wrong?

/Andreas

Private Sub Kommandoknapp0_Click()
sExport "c:\test.txt", "exportfil"
End Sub

Private Function sExport(strFil As String, strFraga As String)

Dim f As Integer
'If Dir(strFil) <> "" Then
' If MsgBox("File exists, overwrite?", vbYesNo + vbQuestion + vbDefaultButton2) = vbNo Then Exit Function
'End If
f = FreeFile
Open strFil For Output As f

Dim DBS As Database, RST As Recordset
Set DBS = CurrentDb
Dim a As Field
Dim strExp As String


Set RST = DBS.OpenRecordset(strFraga)
strExp = ""
'For Each a In RST.Fields
' strExp = strExp & ";" & a.Name
' MsgBox strExp
'Next
'Print #f, Right(strExp, Len(strExp) - 1)

With RST
While Not .EOF
strExp = ""
For Each a In .Fields
strExp = Trim(strExp) & ";" & Trim(a)
'MsgBox strExp
Next
Print #f, Right(strExp, Len(strExp) - 1)
.MoveNext
Wend
End With
Set RST = Nothing

Close f

MsgBox strFil & " klar!"
End Function
 
menu Tools -> References ...
Tick the latest Microsoft DAO x.y Object Library

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top