A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

SQL behind a form's control



 
 
Thread Tools Display Modes
  #1  
Old January 26th, 2006, 08:49 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default SQL behind a form's control

I have a textbox control (PO) on a form (frmInvoice) which I would like to
populate with the result of a query.

SELECT TblInvoice.[Purchase Order]
FROM TblInvoice
WHERE (TblInvoice.InvoiceID)= (SELECT Max(InvoiceID) FROM TblInvoice
WHERE([TblInvoice].[Company_ID]=[Forms]![FrmInvoice]![Company_ID]));

I would like to associate the result of querry above with the On Enter event
of the control (PO) so that the querry's result will become the control's
default value.

Can somebody help with the VBA syntax?
  #2  
Old January 27th, 2006, 12:27 AM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default SQL behind a form's control

Why not just use the DMax function instead? Put it in the form's On Current
event.

Me.(PO).DefaultValue =
nz(Dmax("InvoiceID","TblInvoice","[TblInvoice].[CompanyID =" &
Me.CompanyID),0)

Brian


"Rafi" wrote in message
...
I have a textbox control (PO) on a form (frmInvoice) which I would like to
populate with the result of a query.

SELECT TblInvoice.[Purchase Order]
FROM TblInvoice
WHERE (TblInvoice.InvoiceID)= (SELECT Max(InvoiceID) FROM TblInvoice
WHERE([TblInvoice].[Company_ID]=[Forms]![FrmInvoice]![Company_ID]));

I would like to associate the result of querry above with the On Enter

event
of the control (PO) so that the querry's result will become the control's
default value.

Can somebody help with the VBA syntax?



  #3  
Old January 27th, 2006, 01:16 AM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default SQL behind a form's control

Or if you prefer,

Dim db As Dao.Database
Dim rs as Dao.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT TblInvoice.[Purchase Order] .....

Me.PO.DefaultValue = rs!InvoiceID

rs.Close
db.Close
set db = Nothing

Brian

"Brian Bastl" wrote in message
...
Why not just use the DMax function instead? Put it in the form's On

Current
event.

Me.(PO).DefaultValue =
nz(Dmax("InvoiceID","TblInvoice","[TblInvoice].[CompanyID =" &
Me.CompanyID),0)

Brian


"Rafi" wrote in message
...
I have a textbox control (PO) on a form (frmInvoice) which I would like

to
populate with the result of a query.

SELECT TblInvoice.[Purchase Order]
FROM TblInvoice
WHERE (TblInvoice.InvoiceID)= (SELECT Max(InvoiceID) FROM TblInvoice
WHERE([TblInvoice].[Company_ID]=[Forms]![FrmInvoice]![Company_ID]));

I would like to associate the result of querry above with the On Enter

event
of the control (PO) so that the querry's result will become the

control's
default value.

Can somebody help with the VBA syntax?





 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What Are The Issues With MS Access Client to SQL Server DB Smithers General Discussion 13 January 9th, 2006 03:14 PM
combo box, control source, and sql statements anonymous Using Forms 1 October 18th, 2005 05:48 PM
Unable to insert record to Access via SQL from an ASP page Norman Yuan General Discussion 1 February 2nd, 2005 08:23 PM
Forms Toolbar vs. Control Toolbox vs. Data Validation for drop dow Scott General Discussion 1 February 1st, 2005 01:51 PM
Access Calendar lost General Discussion 2 July 7th, 2004 04:58 AM


All times are GMT +1. The time now is 12:31 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.