Form Buttons/validation rule vb (1 Viewer)

Antony Cole

Registered User.
Local time
Today, 14:01
Joined
Mar 14, 2012
Messages
16
Hi all, hope someone can help.

I have a form which contains various info. What i'm interested in is I have a button called (Create Job), when pressed displays a message box yes/no then depending which option you choose (Yes) runs a query based on that form. What I have on the current form is a combo box which contains words "awaiting authorisation", "Authorised", and "Cancelled". I need to write a piece of code in there somewhere that unless "authorised" is selected in the combo box the query will not run when the button is pressed and also throws up a message to tell me so. Hope someone can help

Thanks

Antony
 

John Big Booty

AWF VIP
Local time
Tomorrow, 07:01
Joined
Aug 29, 2005
Messages
8,262
Welcome to the forum;

Try the following in the On Click event of your button;
Code:
If MsgBox("Do you wish to run a query?", vbYesNo, "Warning") = vbYes Then  [COLOR="SeaGreen"]'Test for Yes response to Message box[/COLOR]
     If Me.YourComboName.Text <> "Authorised" Then   [COLOR="SeaGreen"]'Test for the text [B]Authorised[/B] in your combo box and exit sub routine if it doesn't[/COLOR]
          MsgBox "Sorry record must be Authorised, can't run query"
          Exit Sub
     Endif

     DoCmd.[URL="http://msdn.microsoft.com/en-us/library/bb238028%28v=office.12%29.aspx"]OpenQuery[/URL] "YOurQueryName"  [COLOR="SeaGreen"]'Run query[/COLOR]
     MsgBox "Query Successfully run" [COLOR="SeaGreen"] 'superfluous message box can safety be removed [/COLOR]
Else                                                                      
     MsgBox "You clicked No. the query will not be run"  [COLOR="SeaGreen"]'No response to first Message box. If not required this line and the line above [B]Else[/B] can safety be removed[/COLOR]
End If
 

Antony Cole

Registered User.
Local time
Today, 14:01
Joined
Mar 14, 2012
Messages
16
Print record as report problem

Thanks for all your help much appreciated. I now have a new problem I need help with if you could. I have this code:

Private Sub Command52_Click()
Dim strReportName As String
Dim strCriteria As String

strReportName = "QuoteDetailsT1"
strCriteria = "[Quote Ref]='" & Me![Quote Ref] & "'"
DoCmd.OpenReport strReportName, acViewNormal, , strCriteria

End Sub

I get a runtime error 3464 data mismatch
I think I know what the problem is but can't find a solution. The Quote Ref is a autonumber which I formatted so that the numbers all start with Q1, Q2 etc Format=(\Q0)

Hope you can help, thanks

Antony
 

John Big Booty

AWF VIP
Local time
Tomorrow, 07:01
Joined
Aug 29, 2005
Messages
8,262
Given that Quote Ref is a numeric value you do not need to enclose it in quote marks as you have done. it is only String values that require this.

The following should now work;

Code:
Private Sub Command52_Click()
Dim strReportName As String
Dim strCriteria As [COLOR="Red"]Integer[/COLOR]

strReportName = "QuoteDetailsT1"
strCriteria = "[Quote Ref]=" & Me![Quote Ref]
DoCmd.OpenReport strReportName, acViewNormal, , strCriteria

End Sub

In future when posting code please use the hash (#) to enclose your code in Code tags. You can then format your code making it easier to read and follow.
 

Users who are viewing this thread

Top Bottom