Topics Search

DoCmd Where Condition

DoCmd Where Condition
Views: 22
I have a report and on the onclick event of a texbox in the report I am trying to open a form and for it to filter on the Admin Name.

The Admin Name is displayed on the report, however when I click on the text box pop-up appears 'AdminName' and a input box, if I typed in the name the form opens blank, what am I doing wrong?

Private Sub Cleansed_Click()
Dim AdminName As String
AdminName = Me.Admin_Name
DoCmd.OpenForm "Cleansed Clients", acNormal, , "[AdminName] = [Forms]![Cleansed Clients]![Admin Name]" End Sub
Sponsored Links:

Similar posts...


DoCmd.OutputTo AcFormatPDF

DoCmd.OutputTo AcFormatPDF Icon
I'm trying to use DoCmd.OutputTo to save a report as a PDF file. The trouble I'm having is that it seems to ignore the formatting set in VBA. In this case if a certain condition is true thePageHeader is hidden, the problem is that DoCmd.OutputTo prints that header even if the condition is true.

Is there a way around it? Am I missing something?

Using where condition of DoCmd.BrowseTo with navigation form (Access 2010)

Using where condition of DoCmd.BrowseTo with navigation form (Access 2010) Icon
I now can successfully get Access to open the navigation formto the correct tab using DoCmd.BrowseTo.

DoCmd.BrowseTo acBrowseToForm, "frmGuestInfo", "Main.NavigationSubform", "[GuestID] = " & lngGuestID

The secret was that I had to close the search form that was in use, so that the already open navigation form, "Main", would be visible, or the active form.

However, I cannot get the where condition to work at all. It has been some years since I worked with Access, so I'm sure I'm probably missing something simple, but I have tried many variations of ways to specify the where condition.

I was able to specify a filter on the form in question, frmGuestInfo, that worked as expected, but the same filter did not work when specified as the where condition of the DoCmd.BrowseTo command. lngGuestID does evaluate in code properly, so that is not the problem.

Open Report or Form depending on condition

Open Report or Form depending on condition Icon
I have a form that needs to either open a report if one condition is met or open a form if that same condition is not met. i can do one as well as the other but I can't get them to work together. There seems to be an issue using Openform and Openreport together. Any help is appreciate. This is what I have so far:

Private Sub RCRA_Continue_Click()
If Me.[dot_transport?] = "-1" Then
DoCmd.OpenForm "frm_DOT"
DoCmd.OpenReport "output"
End If
End Sub

The condition is DOT_Transport? and the Form is frm_DOT while the report is Output.

Difference between using Query based Report and Where Condition in OpenReport

Difference between using Query based Report and Where Condition in OpenReport Icon
I was just wondering what the difference between using a report based on a query, where one field in the query has a parameter as a criteria, and the where condition in docmd.openreport is?

For example, I wanted to create a receipt type report that would would open based on a transaction number. So I created a query that prompts for transaction number and then based a report on that query.

Now I am trying to get a button to perform some code (which I have already tested and is working) and open the report based on the transactions number. I would have thought I would need VBA to fill in the transaction number, but I can't get that syntax correct, and adding a where condition doesn't seem to work either.

Here is a sample of my syntax:

MsgBox "Would you like to print a receipt?", vbYesNo,
If vbYes Then DoCmd.OpenReport "Check_Out_Receipt_rpt", acViewPreview, , NextTransactionNum
ElseIf vbNo Then
MsgBox "Receipt will not be printed"
End If

Where NextTransactionNum is a number that is populated via prior code my taking the max of the numbers in a particular field in a table and adding 1.

VBA Loop through, check condition, replace

VBA Loop through, check condition, replace Icon
I want to write a vba code to loop through a column in my table and check for a condition, and where it does not equal that condition I want it to display the whole row in a message box and ask to amend the field to meet that condition. If I say Yes I want the amendment to proceed.

For example, the fields would be mostly say 31/08/2012 but one entry may be 30/07/2012. I want the code to pick this out and suggest whether I want to change this to 31/08/2012.

OpenReport function

OpenReport function Icon
I wrote this function in a click event of a boutton

DoCmd.OpenReport "customer_account", acViewPreview, , "[nam]='" & Me.Combo4 & "'"

can I add another condition beside the one in the function. In other words, the last partion of the OpenReport function (condition) could be more than one.

How can I hide/unhide DB window with a single button?

How can I hide/unhide DB window with a single button? Icon
I'm trying to hide/unhide database window, I've got some idea from the web.
Private Sub cmdHide_Click()
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
End Sub
Private Sub cmdShow_Click()
DoCmd.SelectObject acTable, , True
End Sub

It works but it needs two buttons, one for hide and one for unhide.

I guess there must be some way to combine them into one button with if statement or something like that.

But how do I know if DB window has been hidden or not? So that I can put it into if statement as condition? Or are there any other ways to do that

Print Question

Print Question Icon
I have a macro that generates a report based on a query with a date range condition and a field value condition of -1. When the macro runs and both conditions are met I get what I want. However when the -1 condition fails, or is 0, I still get the report with #error which is to be expected.

I have tried using the where conditon field in the macro and set it so the field value is equal to -1 but I still get the report with the #Error.

Is there a way to not have the report print when the second condition is not -1?

DoCmd OpenReport ... where condition with a Like

DoCmd OpenReport ... where condition with a Like Icon
DoCmd.OpenReport "R_Client_Job", acViewReport, , "Job_Name Like *" & Txt_KeyWord & "*"

this is my code and I always get error 3075 missing operator or something and it's bothering me. I did this with a macro but now I need to do it with vb since the macro can't do as much some code can

Iif condition in a macro

Iif condition in a macro Icon
Was hoping to get some help setting up an Iif condition.
I have a RunApp Action set up and would like to place an Iif condition next to it basically stating if today's date is a Saturday, quit application.

What I have tried is this and it does not work: Iif(Date(), "dddd")="Saturday"
I have the Quit Action below the RunApp Action, so if the condition is met it will quit the app, if condition is not met run the app