Urgent Help Needed with Lookup code...Please!!! 
Author Message
 Urgent Help Needed with Lookup code...Please!!!

Can someone help me with the code below, or suggest a better way to do what
I am attempting to do?  What I want to do is retrieve the titles that match
the one the user enters in txtTitleSearch when cmdTitleSearch is clicked.  I
am not an Access developer I just happen to have to give support for a
product created by someone else...so chances are the code I have here is
incomplete. Here is what I have so far but I am getting syntax errors in the
SQL look-a-like piece of code...any help I can get on this would be greatly
appreciated. Thanks in advance.

Private Sub cmdTitleSearch_Click()
On Error GoTo Err_cmdTitleSearch_Click

    Dim db As Database
    Dim rs As Recordset

    Set db = CurrentDb()
    Set rs = db.OpenRecordset("SELECT OrderDetails.OrderID,
OrderDetails.StandardNumber,
                                              OrderDetails.InvoiceNumber ,
resource.Title, resource.Author,
                                              resource.PublicationDate ,
resource.Edition
                                              FROM OrderDetails INNER JOIN
Resource ON (Resource.ResourceID =
                                               OrderDetails.ResourceID)
                                              WHERE((Resource.Title) Like '"
& txtTitleSearch & "*');")

Exit_cmdTitleSearch_Click:
    Exit Sub

Err_cmdTitleSearch_Click:
    MsgBox Err.Description
    Resume Exit_cmdTitleSearch_Click

End Sub

 J. Wilson



Mon, 31 May 2004 05:18:20 GMT  
 Urgent Help Needed with Lookup code...Please!!!
Janice,
In addition to the other suggestion, you could try letting Access generate
the correct SQL. Try creating a query that produces the exact output you
desire. Then, select View/View SQL in the query window and copy/paste the
SQL string into the SQL string variable in your function.
Susan


Quote:
> Can someone help me with the code below, or suggest a better way to do
what
> I am attempting to do?  What I want to do is retrieve the titles that
match
> the one the user enters in txtTitleSearch when cmdTitleSearch is clicked.
I
> am not an Access developer I just happen to have to give support for a
> product created by someone else...so chances are the code I have here is
> incomplete. Here is what I have so far but I am getting syntax errors in
the
> SQL look-a-like piece of code...any help I can get on this would be
greatly
> appreciated. Thanks in advance.

> Private Sub cmdTitleSearch_Click()
> On Error GoTo Err_cmdTitleSearch_Click

>     Dim db As Database
>     Dim rs As Recordset

>     Set db = CurrentDb()
>     Set rs = db.OpenRecordset("SELECT OrderDetails.OrderID,
> OrderDetails.StandardNumber,
>                                               OrderDetails.InvoiceNumber ,
> resource.Title, resource.Author,
>                                               resource.PublicationDate ,
> resource.Edition
>                                               FROM OrderDetails INNER JOIN
> Resource ON (Resource.ResourceID =
>                                                OrderDetails.ResourceID)
>                                               WHERE((Resource.Title) Like
'"
> & txtTitleSearch & "*');")

> Exit_cmdTitleSearch_Click:
>     Exit Sub

> Err_cmdTitleSearch_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdTitleSearch_Click

> End Sub

>  J. Wilson



Mon, 31 May 2004 06:13:04 GMT  
 Urgent Help Needed with Lookup code...Please!!!
Your code is incomplete as I questioned in the previous thread.  Also, since
you use A2K (which by default uses ADO Library, not DAO Library needed for
your code), you get the Compile error on the Dim db as Database as Database
is a DAO object, not ADO object.  For more info., see the  'Articles'
section at

http://www11.ewebcity.com/brenreyn

However, if you only need to retrieve the *first* Title in the Table
[Resource] that starts with the user's input in the TextBox all you need is
the DLookUp function.

If you want all the Titles from the Table [Resource] that start with the
user's input, then you have to decide what to do with all the matched
Titles.

Your code looks like you want to retrieve Records using Recordset rather
than just the Titles.  The code sets up the Recordset then abruptly ends
without doing anything with the Recordset.  Basically, the code does nothing
for you except giving you Compile error above and potentially locking up the
PC memory.

Perhaps, you need to expand / explain what you want to do with the Title(s)
/ Records retrieved before respondents can help further.

HTH
Van T. Dinh


Quote:
> Can someone help me with the code below, or suggest a better way to do
what
> I am attempting to do?  What I want to do is retrieve the titles that
match
> the one the user enters in txtTitleSearch when cmdTitleSearch is clicked.
I
> am not an Access developer I just happen to have to give support for a
> product created by someone else...so chances are the code I have here is
> incomplete. Here is what I have so far but I am getting syntax errors in
the
> SQL look-a-like piece of code...any help I can get on this would be
greatly
> appreciated. Thanks in advance.

> Private Sub cmdTitleSearch_Click()
> On Error GoTo Err_cmdTitleSearch_Click

>     Dim db As Database
>     Dim rs As Recordset

>     Set db = CurrentDb()
>     Set rs = db.OpenRecordset("SELECT OrderDetails.OrderID,
> OrderDetails.StandardNumber,
>                                               OrderDetails.InvoiceNumber ,
> resource.Title, resource.Author,
>                                               resource.PublicationDate ,
> resource.Edition
>                                               FROM OrderDetails INNER JOIN
> Resource ON (Resource.ResourceID =
>                                                OrderDetails.ResourceID)
>                                               WHERE((Resource.Title) Like
'"
> & txtTitleSearch & "*');")

> Exit_cmdTitleSearch_Click:
>     Exit Sub

> Err_cmdTitleSearch_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdTitleSearch_Click

> End Sub

>  J. Wilson



Mon, 31 May 2004 10:09:48 GMT  
 Urgent Help Needed with Lookup code...Please!!!
I just need to display the result table. And yes this would be data
pertaining to all titles that begins with the user's input.



Quote:
> Your code is incomplete as I questioned in the previous thread.  Also,
since
> you use A2K (which by default uses ADO Library, not DAO Library needed for
> your code), you get the Compile error on the Dim db as Database as
Database
> is a DAO object, not ADO object.  For more info., see the  'Articles'
> section at

> http://www11.ewebcity.com/brenreyn

> However, if you only need to retrieve the *first* Title in the Table
> [Resource] that starts with the user's input in the TextBox all you need
is
> the DLookUp function.

> If you want all the Titles from the Table [Resource] that start with the
> user's input, then you have to decide what to do with all the matched
> Titles.

> Your code looks like you want to retrieve Records using Recordset rather
> than just the Titles.  The code sets up the Recordset then abruptly ends
> without doing anything with the Recordset.  Basically, the code does
nothing
> for you except giving you Compile error above and potentially locking up
the
> PC memory.

> Perhaps, you need to expand / explain what you want to do with the
Title(s)
> / Records retrieved before respondents can help further.

> HTH
> Van T. Dinh



> > Can someone help me with the code below, or suggest a better way to do
> what
> > I am attempting to do?  What I want to do is retrieve the titles that
> match
> > the one the user enters in txtTitleSearch when cmdTitleSearch is
clicked.
> I
> > am not an Access developer I just happen to have to give support for a
> > product created by someone else...so chances are the code I have here is
> > incomplete. Here is what I have so far but I am getting syntax errors in
> the
> > SQL look-a-like piece of code...any help I can get on this would be
> greatly
> > appreciated. Thanks in advance.

> > Private Sub cmdTitleSearch_Click()
> > On Error GoTo Err_cmdTitleSearch_Click

> >     Dim db As Database
> >     Dim rs As Recordset

> >     Set db = CurrentDb()
> >     Set rs = db.OpenRecordset("SELECT OrderDetails.OrderID,
> > OrderDetails.StandardNumber,
> >                                               OrderDetails.InvoiceNumber
,
> > resource.Title, resource.Author,
> >                                               resource.PublicationDate ,
> > resource.Edition
> >                                               FROM OrderDetails INNER
JOIN
> > Resource ON (Resource.ResourceID =
> >                                                OrderDetails.ResourceID)
> >                                               WHERE((Resource.Title)
Like
> '"
> > & txtTitleSearch & "*');")

> > Exit_cmdTitleSearch_Click:
> >     Exit Sub

> > Err_cmdTitleSearch_Click:
> >     MsgBox Err.Description
> >     Resume Exit_cmdTitleSearch_Click

> > End Sub

> >  J. Wilson



Mon, 31 May 2004 23:32:23 GMT  
 Urgent Help Needed with Lookup code...Please!!!
The easiest way would be:

1.  Create a saved Query with the SQL String:

SELECT OrderDetails.OrderID, OrderDetails.StandardNumber,
    OrderDetails.InvoiceNumber,
    resource.Title, resource.Author, resource.PublicationDate,
resource.Edition
FROM OrderDetails INNER JOIN Resource
    ON (Resource.ResourceID = OrderDetails.ResourceID)
WHERE((Resource.Title) Like Forms!YourFormName.txtTitleSearch & "*";

Name this Query "qselMatchedTitles"

2.  Then change your code to simply:

****Warning: Untested code****
Private Sub cmdTitleSearch_Click()
On Error GoTo Err_cmdTitleSearch_Click

    DoCmd.OpenQuery "qselMatchedTitles"

Exit_cmdTitleSearch_Click:
    Exit Sub

Err_cmdTitleSearch_Click:
    MsgBox Err.Description
    Resume Exit_cmdTitleSearch_Click

End Sub
****Code ends****

Check Access Help on OpenQuery Method for additional options.

HTH
Van T. Dinh


Quote:
> I just need to display the result table. And yes this would be data
> pertaining to all titles that begins with the user's input.



Tue, 01 Jun 2004 12:13:40 GMT  
 Urgent Help Needed with Lookup code...Please!!!
The solution Van Thien offered below was the first thing I tried but the
resulting table would only display a blank record.  So I abandoned that
approach for the one I was requesting help with. The code at that point had
looked like this:

saved Query:
SELECT OrderDetails.OrderID, OrderDetails.ResourceID AS
OrderDetails_ResourceID, OrderDetails.StandardNumber,
OrderDetails.InvoiceNumber, Resource.Author, Resource.Title,
Resource.Publisher, Resource.PublicationDate, Resource.Edition
FROM Resource INNER JOIN OrderDetails ON Resource.ResourceID =
OrderDetails.ResourceID
WHERE (((Resource.Title) Like [forms]![frmInvoice
Maintenance].[txtTitleSearch] & "*"))
ORDER BY OrderDetails.ResourceID;

Procedure:
Private Sub cmdTitleSearch_Click()
On Error GoTo Err_cmdTitleSearch_Click

    Dim QryName As String

    QryName = "TitleSearch Query"
    DoCmd.OpenQuery QryName, acViewNormal, acReadOnly

Exit_cmdTitleSearch_Click:
    Exit Sub

Err_cmdTitleSearch_Click:
    MsgBox Err.Description
    Resume Exit_cmdTitleSearch_Click

End Sub

Anyway thanks all for your help I will just keep at it until I find
something ... WELL what do you know I decided to try it again before I post
this message the only thing I changed was that I took out the ORDER BY
clause and it worked fine.  That doesn't make sense to me but I'm glad it
works anyway thanks again!

Janice Wilson



Quote:
> The easiest way would be:

> 1.  Create a saved Query with the SQL String:

> SELECT OrderDetails.OrderID, OrderDetails.StandardNumber,
>     OrderDetails.InvoiceNumber,
>     resource.Title, resource.Author, resource.PublicationDate,
> resource.Edition
> FROM OrderDetails INNER JOIN Resource
>     ON (Resource.ResourceID = OrderDetails.ResourceID)
> WHERE((Resource.Title) Like Forms!YourFormName.txtTitleSearch & "*";

> Name this Query "qselMatchedTitles"

> 2.  Then change your code to simply:

> ****Warning: Untested code****
> Private Sub cmdTitleSearch_Click()
> On Error GoTo Err_cmdTitleSearch_Click

>     DoCmd.OpenQuery "qselMatchedTitles"

> Exit_cmdTitleSearch_Click:
>     Exit Sub

> Err_cmdTitleSearch_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdTitleSearch_Click

> End Sub
> ****Code ends****

> Check Access Help on OpenQuery Method for additional options.

> HTH
> Van T. Dinh



> > I just need to display the result table. And yes this would be data
> > pertaining to all titles that begins with the user's input.



Wed, 02 Jun 2004 02:33:08 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Urgent help needed please help

2. URGENT help needed, please help

3. Urgent help needed please help

4. Urgent help needed please help

5. Newbies need help......Urgent please help!!

6. Please Help Urgent help needed!!!!

7. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

8. API callbacks - need help / example code - PLEASE PLEASE!!!

9. Urgent shell help needed (Command Code)

10. Need some help with some Access coding if someone could please help =)

11. I NEED HELP !!!! URGENT PLEASE

12. URGENT HELP PLEASE PLEASE PLEASE???

 

 
Powered by phpBB® Forum Software