Error On click Button Docmd Report Error 3464 - ms-access

Hi Everyone How Are You I hope You Are Well.
I Am Working On A MS Access Application And Want Fetch Result From List Box With On Click Button
But I'm Facing A Error Data Type Mismatch In Criteria expression
Here is My Code On Click Button
Private Sub ViewBalance_Click()
'Dim listrpt As String
If IsNull(listrpt) Then
MsgBox "Please Select The Account Name", vbOKOnly, "Warning"
Exit Sub
End If
DoCmd.OpenReport "List All Parties Balance", acViewPreview, , "[Account ID] = """ & listrpt &
""""
Me.FilterOn = True
End Sub
And Here is My On Report Load Filter But This Filter Working Fine Above Code Give me Error
Report Load Code
Private Sub Report_Load()
DoCmd.Maximize
If MsgBox("Do You Want To Filter Available Balance Only?", vbYesNo + vbQuestion) = vbYes Then
Dim strFilter As String
strFilter = "[RQ]>0"
'verify that it looks good
Me.Filter = strFilter
Me.FilterOn = True
End If
End Sub
Report Name: List All Parties Balance
Query Name Where is Field Name: Account ID is: ListBalance
And listrpt Response Account ID = 60023
Please Anyone Give me A Support & Help Thanks in Advance

Related

DoEvent() Returns 0 BUT Run-time Error 2585 This action can't be carried out while processing a form or report event

This code was running without a hitch, but now getting Error 2585.
I have looked at Gustav's answer and Gord Thompson's answer but unless I am missing something (quite possible!) the first does not work and the second seems inapplicable. I saw on another site a suggestion that there might be a duplicate record ID, but I check for that possibility.
I put a call to DoEvent() in response to this error but it returns zero. I also wait for 10 seconds to let other processes run. Still receive the error.
Private Sub SaveData_Click()
Dim myForm As Form
Dim myTextBox As TextBox
Dim myDate As Date
Dim myResponse As Integer
If IsNull(Forms!Ecoli_Data!DateCollected.Value) Then
myReponse = myResponse = MsgBox("You have not entered all the required data. You may quit data entry by hitting 'Cancel'", vbOKOnly, "No Sample Date")
Forms!Ecoli_Data.SetFocus
Forms!Ecoli_Data!Collected_By.SetFocus
GoTo endOfSub
End If
If Me.Dirty Then Me.Dirty = False
myDate = Me.DateCollected.Value
Dim yearAsString As String, monthAsString As String, dayAsString As String, clientInitial As String
Dim reportNumberText As String
reportNumberText = Me!SampleNumber.Value
Debug.Print "reportNumberText = " & reportNumberText
Debug.Print "CollectedBy Index: " & Me!Collected_By & " Employee Name: " & DLookup("CollectedBy", "Data_Lookup", Me.Collected_By)
Dim whereString As String
whereString = "SampleNumber=" & "'" & reportNumberText & "'"
Debug.Print whereString
On Error GoTo errorHandling
DoCmd.OpenReport "ECOLI_Laboratory_Report", acViewPreview, , whereString
DoCmd.PrintOut
DoCmd.Close acReport, "ECOLI_Laboratory_Report", acSaveNo
Dim eventsOpen As Integer
eventsOpen = DoEvents()
Debug.Print "Number of Open Events = " & DoEvents()
Dim PauseTime, Start, Finish, TotalTime
PauseTime = 10 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.
myResponse = MsgBox("Processing Report Took " & TotalTime & " seconds.", vbOKOnly)
myResponse = MsgBox("Do you want to add more data?", vbYesNo, "What Next?")
If myResponse = vbYes Then
DoCmd.Close acForm, "ECOLI_Data", acSaveYes
Error Generated By Line Above and occurs whether response Y or N to MsgBox.
DoCmd.OpenForm "ECOLI_Data", acNormal, , , acFormAdd
DoCmd.GoToRecord , , acNewRec
Else
DoCmd.Close acForm, "ECOLI_Data", acSaveYes
End If
Exit Sub
errorHandling:
If Err.Number = 2501 Then
myResponse = MsgBox("Printing Job Cancelled", vbOkayOnly, "Report Not Printed")
ElseIf Err.Number = 0 Then
'Do nothing
Else
Debug.Print "Error Number: " & Err.Number & ": " & Err.Description
myResponse = MsgBox("An Error occurred: " & Err.Description, vbOKOnly, "Error #" & Err.Number)
End If
If Application.CurrentProject.AllForms("ECOLI_Data").IsLoaded Then DoCmd.Close acForm, "ECOLI_Data", acSaveNo
If Application.CurrentProject.AllReports("ECOLI_Laboratory_Report").IsLoaded Then DoCmd.Close acReport, "ECOLI_Laboratory_Report", acSaveNo
endOfSub:
End Sub
Any idea on what am I missing here? Thanks.
I can't replicate the problem, but the following might help:
I assume you run into troubles because you're closing and opening the form in the same operation. To avoid doing this, you can open up a second copy of the form, and close the form once the second copy is open. This avoids that issue.
To open a second copy of the form:
Public Myself As Form
Public Sub CopyMe()
Dim myCopy As New Form_CopyForm
myCopy.Visible = True
Set myCopy.Myself = myCopy
End Sub
(CopyForm is the form name)
To close a form that may or may not be a form created by this function
Public Sub CloseMe()
If Myself Is Nothing Then
DoCmd.Close acForm, Me.Name
Else
Set Myself = Nothing
End If
End Sub
More information on having multiple variants of the same form open can be found here, but my approach differs from the approach suggested here, and doesn't require a second object to hold references and manage copies.
This line of code
`DoCmd.Close acForm, "ECOLI_Data", acSaveYes`
doesn't save the record you are on, it just saves any changes to the form design.
You should probably use
If Me.Dirty Then Me.dirty = False
to force a save of the current record if any data has changed.

Ms Access filter reports in runtime mode

Does anyone knows how to filter reports the right way within Access runtime mode?
The usual code with DoCmd doesn't work.
This is what I tried for the report:
Private Sub Befehl217_Click()
DoCmd.OpenReport "Tagesbericht", acViewPreview
End Sub
Private Sub Bezeichnungsfeld26_Click()
DoCmd.GoToControl "DateFilter"
DoCmd.RunCommand acCmdFilterMenu
End Sub
This didn't work. Access complained that "FilterMenu isn't available".
I tried to create a context menu but this only displayed me cut, copy and paste.
You confirmed your report includes a control named Bezeichnungsfeld26 and when the user clicks in that control, you want to bring up the filter menu for that control.
When the user clicks in that control, it has the focus, so there is no need for GoToControl. And you don't want to go to a different control if you want the user to filter on Bezeichnungsfeld26.
Disable the GoToControl line ...
Private Sub Bezeichnungsfeld26_Click()
'DoCmd.GoToControl "DateFilter"
DoCmd.RunCommand acCmdFilterMenu
End Sub
You can use the Filter property:
Me.Filter = "[YourField] = " & somevalue & ""
Me.FilterOn = True
or, to expand on your current method:
DoCmd.OpenReport "Tagesbericht", acViewPreview, , "[YourField] = " & somevalue & ""
If you filter for a date you must pass a properly formatted string expression for the date:
Dim FilterDate As Date
FilterDate = Date
DoCmd.OpenReport "Tagesbericht", acViewPreview, , "[DateFilter] = #" & Format(FilterDate, "yyyy\/mm\/dd") & "#"

Access report - Recordsetclone as. Recordsource

I have a form, which has button for report. I want to set Report .Recordsource to whatever on screen is, so basically I need .RecordsetClone of form send to Report. Here is what I tried, but It doesn't work:
Me.Recordsource= Forms!Myform.RecordsetClone
I get an invalid argument on that. Any ideas how to solve this ?
EDIT:
I tried this too - this button is placed on form which has records and opens Report :
Private Sub cmdOpenReport_Click()
DoCmd.OpenReport "MyReport", acViewReport
Reports![MyReport].RecordSource = Me.RecordSource
Reports![MyReport].Filter = Me.Filter
Reports![MyReport].FilterOn = True
End Sub
You can't do that, but you may get away with:
Me.RecordSource = Forms!Myform.RecordSource
though that will not include a filter applied to the form. However, the Filter can be copied the same way, and then:
Me.Filter = Forms!Myform.Filter
Me.FilterOn = True
while sorting must be specified in the report the usual way.
Proof of concept
Private Sub Report_Open(Cancel As Integer)
If MsgBox("Mod 2?", vbQuestion + vbYesNo, "Select") = vbYes Then
Me.RecordSource = "Select * From TestTable Where Id Mod 2 = 0"
End If
End Sub
Gustav, this is correct answer. I have opened another thread for that, but I wasn't aware of what is wrong and where. Sorry for crossposting. here is link to my thread:
Access Report - show current recordsource of another form
Dim strWhere As String
Me.Dirty = False
With Me.Recordset.Clone
Do Until .EOF
strWhere = strWhere & "," & !ID
.MoveNext
Loop
End With
strWhere = Mid(strWhere, 2)
DoCmd.OpenReport "MyReport", acViewReport, WhereCondition:="ID In (" & strWhere & ")
Moderators can delete one of the threads, I can't do that.

Setting a value of a field in my table for future use

I have an access Db which was originally written ib Access 2003 but has since been upgraded to Access 2007 - the problem I am experiencing is as follows:
I have a table "tblBookings" which stores all relevant data for a particular clienst booking or quote, the client field of this table is linked to the PK of the CLient Table (tblClients) when a quote is accepted the user opens the main form, selects the client and in a dropdown selects the booking number then proceeds to "Edit booking" where the user can either edit the booking or confirm it. when the user clicks "confirm Booking" cmdButton the open form closes and the "Create Invoice" form opens. From a dropdown list the user selects the booking number and then prints the Pro-Forma Invoice or invoice. the print pro-forma cammand button opens a report that prints the necessary document, when the Print Invoice command is clicked then the print invoice form is opend where the user has the option to record any ayments made against the invoice.
This being said it is essential to first print a pro-forma before printing an invoice so i need to set a yes no field in the table to yes or true if a pro forma has been printed in which case the invoice button will become visible and remain hidden if one has not been printed yet.
the event procedure on cmdProForma is below (this is where I need ti set the yes/no field in the Pro field which is tblBookings and set to a yes/no field.
Private Sub CmdProForma_Click()
Dim rs As New ADODB.Recordset 'recordset of existing refs
Dim t As String 'temp string var
Dim stDocName As String
Dim stLinkCriteria As String
Dim i As Integer 'temp ref variable
i = CInt(Right(txtBRef, 5))
t = [txtBRef]
With rs
.Open "SELECT BRef,Conf,lock,Pro FROM tblBookings WHERE Bref=" & t & ";", CurrentProject.Connection, adOpenDynamic
If .BOF Or .EOF Then 'no such ref
MsgBox "No booking with ref '" & fRef(CInt(t), "B") & "' exists.", vbExclamation, "No booking"
Else 'ref found: open invoice
strSQL = "UPDATE tblBookings SET Pro = True"
'db.Execute strSQL, dbFailOnError
DoCmd.Close acForm, "frmBRefEnter"
' !Form!frmBRefEnter!Pro = True
DoCmd.OpenReport "rptInvoice1", acViewPreview, , "BRef=" & t
DoCmd.OutputTo acOutputReport, "rptInvoice1", acFormatPDF, destDIR & "\Inv\" & fRef(i, "Pro-Forma") & ".pdf"
End If
End With
End Sub
Add the checkbox for proforma printed to the form. It will be a good guide for your users as to why they cannot print an invoice. You can set the properties to Locked=True
Private Sub CmdProForma_Click()
''"From a dropdown list the user selects the booking number",
''so the booking number must exist, no need to check
DoCmd.OpenReport "rptInvoice1", acViewPreview, , "BRef=" & Me.txtBref
DoCmd.OutputTo acOutputReport, "rptInvoice1", _
acFormatPDF, destDIR & "\Inv\" & fRef(i, "Pro-Forma") & ".pdf"
Me.Pro = True ''Checkbox
DoCmd.Close acForm, "frmBRefEnter"
End Sub
For the invoice button:
Me.cmdInvoicePrint.Visible = Me.Pro
If Me.Pro is ticked, Me.Pro will be true and the invoice button will be visible.

MS Access form to edit specific record from a form by providing input through text box

Can someone please help me on this find specific record Edit through MS access Forms
I have Frmfind form where I have one filed "ticket#" is a input text box
another filed was button "find"
When I enter ticket# which is primary key for my table. I need get the the specific ticket# record should be opened in FormEdit mode using VBA code...
So I have another form "frmEdit" of specific record which has to be called from frmfind -> specific input..
note: Ticket# is column in my table whcih it is primary to have the ticket#.
Code:
Option Compare Database
Private Sub find_Click()
If IsNull(Me.Text79) Or Me.Text79 = "" Then
MsgBox "You must enter a Ticket #", vbOKOnly, "Required Data"
Me.Text79.SetFocus
Exit Sub
End If
If [Ticket#] = Me.Text79.Value Then
MsgBox "Record found"
DoCmd.Close
DoCmd.OpenForm "frmEdit"
Else
MsgBox "not matching record"
Me.Text79.SetFocus
End If
End Sub
Private Sub Form_Open(cancel As Integer)
'On open set focus to text box
Me.Text79.SetFocus
End Sub
You can use this code:
Private Sub Command112_Click()
Me.txtSeach.SetFocus
On Error Resume Next
DoCmd.OpenForm "frmEdit", , , "TicketNumber = '" & Nz(Me.text79, "") & "'"
End Sub
Note in above if TicketNumber is in fact a number column and not text, then remove the single quotes and use this:
DoCmd.OpenForm "aa", , , "TicketNumber = " & Nz(Me.text79, "")
Then for your message, just place that code in the forms on-open event that has a cancel:
eg:
Private Sub Form_Open(Cancel As Integer)
If IsNull(Me!TicketNumberID) Then
MsgBox "Please enter a valid Ticket #", vbOKOnly, "Required Data"
Cancel = True
End If
End Sub
The above assumes your search column is ticket number.
You can also use dlookup(), or even dcount(). I think above is less code, but:
Dim strWhere As String
strWhere = "TicketNumber = " & Me.text79
If DCount("*", "tblBookings", strWhere) > 0 Then
code for Record found goes here
Else
code reocrd not found code here
End If
So either way should suffice here.