I am trying to get specific data by entering a value in a TextBox.
-----------------------------------------------------------
Thanks a lot , hope to get an answer soon
-----------------------------------------------------------
Code:
Sub GetData()
blatt = ActiveSheet.Name
zeile = 1
spalte = 1
q = "select * from customers where country='TextBox1.Text'"
x = ODBCQueryDaten(q, blatt, zeile, spalte)
Range("A2").Select
End Sub
* This is the code when i hit the command button i made, where i get the msg"Either Bof or Eof etc.."
but if i change "TextBox1.Text" to a value like 'Germany' i would get the data correct.
------------------------------------------------------------
This is the code where it takes me after getting the error , if needed:
Public Function ODBCQueryDaten(query As String, blatt As String, zeile As Long, spalte As Long) As Boolean
Dim rs As ADODB.Recordset
Dim smax As Long
Dim s As Long
Dim zmax As Long
Dim z As Long
Dim v As Variant
Dim w As String
'Datenbank verbinden
ODBCConnect
'Datensätze holen
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open query, Conn ', adOpenForwardOnly, adLockOptimistic
'Spaltenzahl/Zeilenzahl
smax = rs.Fields.Count
'nix gefunden
If rs.AbsolutePosition = -1 Then
Worksheets(blatt).Cells(zeile, spalte) = "nix"
Else
rs.MoveLast
zmax = rs.RecordCount
End If
'Spaltenüberschriften
For s = 0 To smax - 1
Worksheets(blatt).Cells(zeile, spalte + s) = rs.Fields(s).Name
Next s
zeile = zeile + 1
'Zeilenwerte
rs.MoveFirst
For z = 0 To zmax - 1
'Spaltenwerte
For s = 0 To smax - 1
'Wert konvertieren
Set v = rs.Fields(s)
If IsNull(v) Then
w = "<NULL>"
ElseIf IsEmpty(v) Then
w = "<EMPTY>"
Else
w = Komma2Punkt1(v)
End If
'Wert in Zelle
Worksheets(blatt).Cells(zeile + z, spalte + s) = w
Next s
'nächster Datensatz
rs.MoveNext
Next z
' End If
'Wert zurück
ODBCQueryDaten = True
'Datenbank schliessen
ODBCClose
End Function
Thanks a lot , hope to get an answer soon
Comment