AUTO UPDATE FROM QUERY

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Hello,

I am a new user for MS ACCESS,

I have a form named "order lookup" with criteria of
[forms]![order]![customer ID]

I want to find the field named "Tel" and copy the data in the "order" form
and try to write the code as below :

Private Sub CUSTOMER_ID_AfterUpdate()

DoCmd.OpenForm "order lookup"
Me.[TEL] = Forms![ORDER LOOKUP]![TEL]
DoCmd.Close

End Sub

It's work fine but it's not a good coding, I want to use querydef method but
fail, could you please help send me a code for reference? Thanks in advance!
 
Hi Hello,

I am a new user for MS ACCESS,

I have a form named "order lookup" with criteria of
[forms]![order]![customer ID]

Forms don't have criteria. Queries have criteria. Do you mean that you
based a Form on the query, or what?
I want to find the field named "Tel" and copy the data in the "order" form
and try to write the code as below :

Private Sub CUSTOMER_ID_AfterUpdate()

DoCmd.OpenForm "order lookup"
Me.[TEL] = Forms![ORDER LOOKUP]![TEL]
DoCmd.Close

End Sub

It's work fine but it's not a good coding, I want to use querydef method but
fail, could you please help send me a code for reference? Thanks in advance!

I'd be glad to if I had more than a half a clue as to what you were
trying to accomplish!

John W. Vinson[MVP]
 
Hi John,

Yes, I based a Form on the query, I thought the code I wrote is not good,
could I use the query directly? Appreciate your expert advise!

John Vinson said:
Hi Hello,

I am a new user for MS ACCESS,

I have a form named "order lookup" with criteria of
[forms]![order]![customer ID]

Forms don't have criteria. Queries have criteria. Do you mean that you
based a Form on the query, or what?
I want to find the field named "Tel" and copy the data in the "order" form
and try to write the code as below :

Private Sub CUSTOMER_ID_AfterUpdate()

DoCmd.OpenForm "order lookup"
Me.[TEL] = Forms![ORDER LOOKUP]![TEL]
DoCmd.Close

End Sub

It's work fine but it's not a good coding, I want to use querydef method but
fail, could you please help send me a code for reference? Thanks in advance!

I'd be glad to if I had more than a half a clue as to what you were
trying to accomplish!

John W. Vinson[MVP]
 
Yes, I based a Form on the query, I thought the code I wrote is not good,
could I use the query directly? Appreciate your expert advise!

Sure; just base your Form directly on the query, and open the data
display form using a command button on your search form.

John W. Vinson[MVP]
 
John,

Actually, I want to write a code to accomplish the action.

The code as below but I thought it's not good :

Private Sub CUSTOMER_ID_AfterUpdate()

DoCmd.OpenForm "order lookup"
Me.[TEL] = Forms![ORDER LOOKUP]![TEL]
DoCmd.Close

End Sub

So I try to write another code as below but fail, please advise, thanks!

Private Sub CUSTOMER_ID_AfterUpdate()

Dim qdf As QueryDef
Dim rst As Recordset
Dim db As Database

Set db = CurrentDb
Set qdf = db.QueryDefs("order lookup")
Set rst = qdf.OpenRecordset

Me.TEL = rst.TEL

rst.Close

End Sub
 
Back
Top