Fields as buttons?

keiath
StarLounger
Posts: 73
Joined: 08 Jan 2012, 15:07

Fields as buttons?

Post by keiath »

I have fields that have order numbes invoice numbers,

I would like them to act as a 'button' so that it opens the invoice or order form can this be done?

Thanks

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Fields as buttons?

Post by HansV »

Should the user be able to edit the order number or invoice number?
Best wishes,
Hans

keiath
StarLounger
Posts: 73
Joined: 08 Jan 2012, 15:07

Re: Fields as buttons?

Post by keiath »

No this is a fixed field so no editing allowed. Inovice numbers and ordernumbers cant ever be changed

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Fields as buttons?

Post by HansV »

You can use the On Click event of the text boxes, e.g.

Code: Select all

Private Sub INVOICE_NUMBER_Click()
    DoCmd.OpenForm FormName:="NameOfInvoiceForm", _
        WhereCondition:="INVOICE_NUMBER=" & Me.INVOICE_NUMBER
End Sub
and

Code: Select all

Private Sub ORDER_NUMBER_Click()
    DoCmd.OpenForm FormName:="NameOfOrderForm", _
        WhereCondition:="ORDER_NUMBER=" & Chr(34) & Me.ORDER_NUMBER & Chr(34)
End Sub
Chr(34) is the double quote character.
Best wishes,
Hans

keiath
StarLounger
Posts: 73
Joined: 08 Jan 2012, 15:07

Re: Fields as buttons?

Post by keiath »

I am trying this:-

Private Sub GIN_Click()
DoCmd.OpenForm FormName:="GIN", _
WhereCondition:="GINID=" & Me.GINID
End Sub

But getting a error syantex message, what am I doing wrong?

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Fields as buttons?

Post by HansV »

What does the error message say?
Best wishes,
Hans

keiath
StarLounger
Posts: 73
Joined: 08 Jan 2012, 15:07

Re: Fields as buttons?

Post by keiath »

If 'privatebsub GIN_click() DoCMD is a new marco or marco group, make sure you have saved it and you have typed the name correctly

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Fields as buttons?

Post by HansV »

The code that you posted contains Private Sub, the error message contains privatebsub. Make sure that you have Private Sub.

The code should be created by selecting [Event Procedure] in the On Click event of GIN in the Data tab of the Property Sheet, then clicking the builder dots ... to the right of the dropdown arrow.
Best wishes,
Hans

keiath
StarLounger
Posts: 73
Joined: 08 Jan 2012, 15:07

Re: Fields as buttons?

Post by keiath »

I have it as a Private Sub.

When I now enter this in the expression builder i get this message 'The expression you entered contain invalid syntax

if it helps on the SRN form on the tab collections is where the GIN field is and I want that to open the GIN form

hope that makes sense

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Fields as buttons?

Post by HansV »

You should not enter the code in the expression builder. As mentioned in my previous reply:

The code should be created by selecting [Event Procedure] in the On Click event of GIN in the Data tab of the Property Sheet, then clicking the builder dots ... to the right of the dropdown arrow.
Best wishes,
Hans

keiath
StarLounger
Posts: 73
Joined: 08 Jan 2012, 15:07

Re: Fields as buttons?

Post by keiath »

I think I am getting confused a little am using the expression builder.

I've attached a screen shot so you can see I am in the right area.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Fields as buttons?

Post by HansV »

Once again:
Click the dropdown arrow in the On Click event.
Select [Event Procedure] from the dropdown list. It's the first item in the list:
x925.png
You should see [Event Procedure] in the On Click event.
Now click the "builder dots" button (with ... on it) to the right of the dropdown arrow:
x926.png
This will activate the Visual Basic Editor, where you will see:
x927.png
Change it so that the event procedure looks like this:

Code: Select all

Private Sub GINNO_Click()
    DoCmd.OpenForm FormName:="GIN", WhereCondition:="GINNO=" & Me.GINNO
End Sub
Notice that I use GINNO, since that is the name of the control and of the field. GIN should be the name of the form to be opened.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

keiath
StarLounger
Posts: 73
Joined: 08 Jan 2012, 15:07

Re: Fields as buttons?

Post by keiath »

Thank you, Sorry being a bit slow tonight:)

keiath
StarLounger
Posts: 73
Joined: 08 Jan 2012, 15:07

Re: Fields as buttons?

Post by keiath »

Hi

I have this command:-

Private Sub Stock_Code_Click()
DoCmd.OpenForm FormName:="Stock Control", WhereCondition:="Stock_Code=" & Me.STOCK_CODE
End Sub

But instead of going to the correct stock control form code it display's instead a blank form in stock control

Any ideas what I am doing wrong?
Last edited by keiath on 28 Jan 2012, 17:10, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Fields as buttons?

Post by HansV »

Check whether the Stock Control form has its Data Entry property set to Yes. It should be set to No if you want to view/edit existing records.
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Fields as buttons?

Post by HansV »

Oops - the STOCK_CODE field is text, so you should use

DoCmd.OpenForm FormName:="Stock Control", WhereCondition:="Stock_Code=" & Chr(34) & Me.STOCK_CODE & Chr(34)
Best wishes,
Hans

keiath
StarLounger
Posts: 73
Joined: 08 Jan 2012, 15:07

Re: Fields as buttons?

Post by keiath »

AHHHH Dam text fields lol Again thank you.

I'll have to send you an update, system is looking very good and very 'smart'

Again Thanks for all your help