When you do an OpenRecordset, you put as the first argument either the name
of the query Or the SQL for the query.  You can't pass in a string that has
the name of the query.  It is trying to execute a query where the SQL of the
query is simple

qryDeliveryAddressForQuote

>     Set MyQuery = "qryDeliveryAddressForQuote"
>     Set Myrec = MyDB.OpenRecordset(MyQuery, dbOpenSnapshot)

Instead of the two lines above, simply use the following line:

Set Myrec = MyDB.OpenRecordset("qryDeliveryAddressForQuote", dbOpenSnapshot)

However, there are better ways to do what you want to do.

I would either do a few DLookups and I suggested in
Re: [AccessDevelopers] best way to populate adress fields on a form

or ...

Looks Tom Oakes just saved me time by posting code.

HTH,
Toby

----- Original Message ----- 
From: "jezmo_codpiece" <[EMAIL PROTECTED]>
To: <AccessDevelopers@yahoogroups.com>
Sent: Wednesday, July 13, 2005 9:18 AM
Subject: [AccessDevelopers] Can you check this code please


> I am using the value from a textbox (txtDeliveryAddressID) on the
> form (frmQuote) as a criteria for the query
> qryDeliveryAddressForQuote, so that the query returns the relevant
> address for the record selected on the form. This works fine, if I
> run the query manually I get the correct address. What I want to do
> then is poke the rest of the address fields in to the fields on the
> form, but I cannot get this to work. Essentially I have said that
> when txtDeliveryAddressID changes, run the following code. I have
> only put the city field in so far to test it, but it does t work and
> I cannot see why. Can anybody help please?
>
> Private Sub txtDeliveryAddressID_Change()
> On Error GoTo Err_txtDeliveryAddressID_Change
>
>     Dim MyDB As Database
>     Dim Myrec As DAO.Recordset
>
>     Dim MyQuery As String
>
>     Set MyDB = CurrentDb
>     Set MyQuery = "qryDeliveryAddressForQuote"
>     Set Myrec = MyDB.OpenRecordset(MyQuery, dbOpenSnapshot)
>
>
>     Myrec.MoveFirst
>
>     Set Forms!frmQuote!txtDeliveryCity = Myrec!DeliveryCity
>
>
>     Myrec.Close
>     MyDB.Close
>
>
> Exit_txtDeliveryAddressID_Change:
>     Exit Sub
>
> Err_txtDeliveryAddressID_Change:
>     MsgBox Err.Description
>     Resume Exit_txtDeliveryAddressID_Change
>
> End Sub
>
>
>
>
>
> Please zip all files prior to uploading to Files section.
> Yahoo! Groups Links
>
>
>
>
>
>




Please zip all files prior to uploading to Files section. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AccessDevelopers/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to