Another VB Problem (1 Viewer)

Fosweb

I could be your Doctor...
Joined
Jun 20, 2003
Messages
594
Location
UNSW. Still.
Gender
Male
HSC
2003
ok.

so - i think we are making this all too complicated for you!
it is so simple when using bound text boxes and the data control.

Assuming your data control is called Data1

Code:
'Run the search.
Data1.RecordSource = "(" & SQLQuery & ")"
Data1.Refresh
That will load the recordset into the data control automatically.

You shouldnt need to worry about any of the lines of code like:
set rs = whatever, or set db = whatever.

To move between found records, just use this:

Code:
Data1.moveFirst/moveNext/MovePrevious/MoveLast etc...
To bring back all the records in the database, so that you can search again, you will need to refresh the data control with an sql query that loads all records again:

Code:
Data1.recordsource = ("SELECT * FROM table1")
Data1.refresh
Just remember, that after every sql query, you have to refresh the data control.
 

Fiona

Member
Joined
Apr 28, 2003
Messages
135
Location
Sydney
Ah yes... That seems so much simpler! I'll have a go when I get back from work... Leaving soon, crap, should get ready...

Thankyou so much, Fosweb! :D
 

Fiona

Member
Joined
Apr 28, 2003
Messages
135
Location
Sydney
Oh dear I must be so frustrating...

"Compile error: Variable not defined" - SQLQuery from the Data1.RecordSource = "(" & SQLQuery & ")" bit... Should I have kept something from previously?
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
SQLQuery should be whatever you want the search to be.

Like Foster already said if you want to get all the records back into the data control you should use

Code:
Data1.RecordSource = "(SELECT * FROM table1)"
In this case, SQLQuery would be "SELECT * FROM table1"
 

Fiona

Member
Joined
Apr 28, 2003
Messages
135
Location
Sydney
Ok, new problemo :)

Run-time error 3075: Syntax error (missing operator) in query expression 'Title='Emma' '&'

where Emma is the item we are searching for in the Title field...
 

Fiona

Member
Joined
Apr 28, 2003
Messages
135
Location
Sydney
In case you need it... Here is what I have:

Code:
Private Sub cmdTitle_Click()
    ' search the database with the SQL string
    ' looking for the person with the name entered
    ' in the textbox
    Set rs = db.OpenRecordset("SELECT * FROM table1 WHERE Title='" & txtSearch.Text & "'")
    datbase.RecordSource = ("SELECT * FROM table1 WHERE Title='" & txtSearch.Text & "' & ")
    datbase.Refresh
    ' this on error resume next will catch errors
    ' if there are no matches in the database
    On Error Resume Next


    ' if there is nothing in the recordset, it means
    ' the search returned nothing. So let the user know
    If Err.Number = 3021 Then
        MsgBox "There are no matches."
    End If
End Sub
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Code:
datbase.RecordSource = ("SELECT * FROM table1 WHERE Title='" & txtSearch.Text & "' & ")
should be
Code:
datbase.RecordSource = ("SELECT * FROM table1 WHERE Title='" & txtSearch.Text & "'")
 

anti

aww.. baby raccoon ^^
Joined
Jul 28, 2002
Messages
2,900
Location
Hurstville
Gender
Undisclosed
HSC
2002
when you get things like syntax errors, check that you haven't misspelled words. parameter errors mean that you haven't filled in all the required parameters (all the things you have to tell a function). you might be able to solve some of the errors on your own just by reading the error description :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top