I am trying to get specific data by entering a value in a TextBox.
----------------------------------------------------------- - 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
What program are you using? Part of the problem is that you are passing the literal text "Textbox1.Text" instead of the value inside the textbox. This is why it works when you plug "Germany" into it. Since there is no country named "Textbox1.Text", you won't get any records returned. You need to split the string out so that it can pull the value that is inside the textbox. Because of the Range("A2").Select line, I'm going to guess you are using Excel, in which case I'm not sure the proper way to reference the value in a textbox, so I'll leave it the same as how you have it and just do the concatenation portion. - q = "select * from customers where country='" & TextBox1.Text & "'"
4 1595
What program are you using? Part of the problem is that you are passing the literal text "Textbox1.Text" instead of the value inside the textbox. This is why it works when you plug "Germany" into it. Since there is no country named "Textbox1.Text", you won't get any records returned. You need to split the string out so that it can pull the value that is inside the textbox. Because of the Range("A2").Select line, I'm going to guess you are using Excel, in which case I'm not sure the proper way to reference the value in a textbox, so I'll leave it the same as how you have it and just do the concatenation portion. - q = "select * from customers where country='" & TextBox1.Text & "'"
Hello Seth , thanks a lot for the reply
yes im using excel and trying to retrieve specific data from mysql databas by giving a value in the textbox. now when i did what you wrote me i got the error msg"run-time erorr 424, object required"
I tried many things to get it work but still i cant get it to read the text from the textbox.
regards
thanks you very much , it works now fine
little change was - q = "select * from customers where country='" & UserForm1.TextBox1.Text & "'"
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Maria |
last post by:
Is there another way to delete the current record in a subform from the main
form, another subform or a sub-subform other than setting focus on a field
in the subform and using run command...
|
by: Prakash |
last post by:
Below is my code to delete a record in a continuous form. I can't
figure out any reason but sometimes (another) record gets deleted
instead of where the record pointer is positioned.
Small table...
|
by: jpatchak |
last post by:
Hello,
I have a main form with one subform. I have a command button on the main form to delete the current record. Below is my code. The tables on which the main form and subform are based...
|
by: Kosmos |
last post by:
Hey ya'll...I can't seem to figure out why I'm getting this error message, but it all started when I added the new line of code with the recSet5.AddNew --- when I ran the first line, the logic worked...
|
by: marcf |
last post by:
Hi Everyone,
Hopefully someone will be able to offer a suggestion to this problem.
I have a multi user CMS running at work which I wrote. Aside from a few bugs everything has been going fine...
|
by: THEAF |
last post by:
i'm trying to create a reminder form, when i add a new reminder its ok but when i try to delete a reminder then i get No Current Record problem.
Form Load
Private Sub Form_Load()
Dim s() As...
|
by: TimSki |
last post by:
Hi,
This is very strange...
I have a simple query using a recordset thus...
set rsID = CreateObject("ADODB.recordset")
searchPhrase = "SELECT blah...."
rsID.Open searchPhrase, oConn
|
by: vikas251074 |
last post by:
Hello sir,
I am facing some problem for which I am trying hard to solve it. But in vain.
This programe is for View/Deletion. When I run program for first time, I select vlan from list and press...
|
by: jbrumbau |
last post by:
Hello,
I have a function that goes through each field in a form and checks if it was changed between itself and the existing recordset. It is used to track changes done in any record when the...
|
by: ramachandradurai |
last post by:
hi, i am getting the error like..
Either EOF or BOF is true, or the current record has been deleted.Requested operation requires the current data.
<%@ LANGUAGE="VBSCRIPT" %>...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |