"operation is not allowed when the object is open" - ms-access

When I am trying to execute the program I am getting an error like "operation is not allowed when the object is open". I'm using vb 6.0 and microsoft access database. here is the source code
Private Sub cmdDelete_Click()
dtaOverhead.Recordset.Open "Delete from variable where SWACTFM= " & txtEntry(0).Text & " And SWBUDACT = " & txtEntry(1).Text & " And SWREMFM = '" & txtEntry(12).Text & "' And SWACTRAW = " & txtEntry(2).Text & " And SWBUDRAW = " & txtEntry(3).Text & " And SWREMRAW = '" & txtEntry(13).Text & "' And SWACTWHS = " & txtEntry(4).Text & " And SWBUDWHS = " & txtEntry(5).Text & " And SWREMWHS = '" & txtEntry(14).Text & "' And SWACTLAB = " & txtEntry(6).Text & " And SWBUDLAB = " & txtEntry(7).Text & " And SWREMLAB = '" & txtEntry(15).Text & "' And SWACTWORK = " & txtEntry(8).Text & " And SWBUDWORK = " & txtEntry(9).Text & " And SWREMWORK = '" & txtEntry(16).Text & "' And SWACTTOTAL = " & txtEntry(10).Text & " And SWBUDTOTAL = " & txtEntry(11).Text & " And SWREMTOTAL = '" & txtEntry(17).Text & "'"
MsgBox "Record deleted successfully !", vbInformation, "Deletion Successful"
Call Filllist
Call clearall
cmdSave.Caption = "&Save"
End Sub

You can't open a Recordset twice (er, without closing it in between anyway).
A DELETE would normally be done using Connection.Execute or Command.Execute, not Recordset.Open.

Related

How can I eliminate #error in SSRS expression

=CStr(First(Fields!AXPPaymentTerm.Value, "SalesInvoiceHeaderFooterDS")) & vbcrlf &
iif(First(Fields!AXPSpotRateCurrency.Value, "SalesInvoiceHeaderFooterDS") = 1,"",
"Rate of exchange : " &
First(Fields!AXPSpotRateCurrency.Value, "SalesInvoiceHeaderFooterDS") & " " &
First(Fields!AXPSpotRate.Value, "SalesInvoiceHeaderFooterDS")
)
=CStr(First(Fields!AXPPaymentTerm.Value, "SalesInvoiceHeaderFooterDS")) & vbcrlf &
iif(CStr(First(Fields!AXPSpotRate.Value, "SalesInvoiceHeaderFooterDS")) = "1","",
"Rate of exchange : " &
First(Fields!AXPSpotRateCurrency.Value, "SalesInvoiceHeaderFooterDS") & " " &
First(Fields!AXPSpotRate.Value, "SalesInvoiceHeaderFooterDS")
)

Subform column and data change at runtime not refreshing on Form

I have Main Form in which There are Two Comobobx.
1. Type of Work (C_Art: Name of Combobox)
Repratur
Maintenance
Optimierung
2. Year (C_Year: Name of Combobox)
2018
2019
On the Main Form There is Bar chart which works perfectly and a subform with a datasheet view.
Overall it looks like .
My Problem is when I select the Year 2019 the Subform view with new header 2019-Jan 2019-Feb ......2019-Dec didn't update and the row give me error as #Name?
The Graph is generating correctly without any Problem.
I am changing the query at runtime as below.
Dim count_Status As String
Dim G_Stoerung As String
'Change the query for Graph
count_Status = "TRANSFORM Count(History_query.[LFD_NR]) AS CountOfLFD_NR " & _
" SELECT History_query.[Anlage] " & _
" FROM History_query " & _
" WHERE History_query.[Anlage] <>Null AND History_query.[WAS]= '" & Me.C_Art & "' AND History_query.[Year]= '" & Me.C_Year & "' " & _
" GROUP BY History_query.[Anlage] " & _
" PIVOT History_query.[Status] "
CurrentDb.QueryDefs("Count_Status_Anlage").sql = count_Status
'Updating the Graph with a new Data
Me.Graph9.Requery
Me!Graph9.ChartTitle.Text = Me.C_Art
'Chnage the query of subform
G_Stoerung = "TRANSFORM Count([History_query].WAS) AS CountOfWAS " & _
" SELECT [History_query].Status " & _
" FROM History_query " & _
" WHERE ((([History_query].WAS)= '" & Me.C_Art & "' ) AND [History_query].Status IN ('Offen','beobachten','In bearbeitung','erledigt') ) " & _
" GROUP BY Status " & _
" Order by (IIf([Status]='Offen',1,IIf([Status]='beobachten',2,IIf([Status]='In bearbeitung',3,IIf([Status]='erledigt',4))))) " & _
" PIVOT Format([Datum],'yyyy-mmm') IN ('" & Me.C_Year & "-Jan','" & Me.C_Year & "-Feb','" & Me.C_Year & "-Mar','" & Me.C_Year & "-Apr','" & Me.C_Year & "-May','" & Me.C_Year & "-Jun','" & Me.C_Year & "-Jul','" & Me.C_Year & "-Aug','" & Me.C_Year & "-Sep','" & Me.C_Year & "-Oct','" & Me.C_Year & "-Nov','" & Me.C_Year & "-Dec') "
CurrentDb.QueryDefs("G_Stoerung_query").sql = G_Stoerung
'Updating the subform with new Data
Me.G_Stoerung_Sub.Form.RecordSource = G_Stoerung
Me.G_Stoerung_Sub.Form.Requery
The #NAME? error would be because textboxes are no longer bound to fields that exist. Make the field names generic and apply filter parameter for year. Or set the subform container SourceObject property to query object instead of form
Edit
G_Stoerung_Sub.SourceObject = ""
G_Stoerung_Sub.SourceObject = "Query.G_Stoerung_query"
updating the source object gives desired result.

Run-time Error '3061' Too few parameters. Expected 8

I'm trying to create a vba code to append some data to a Table named T_Tickets
Below the code I'm using.
Function addticketScheduleChange()
Dim route As String
route = InputBox("Please enter the URL for the ticket:", "Schedule Review")
Set db = CurrentDb
Dim frm As Form
Set frm = Form_Frm_View_Team
sSQL = "Insert INTO T_Tickets ([CSA Login],[Team Manager],[Schedule Description],[WF Shift Pattern],[Mytime Schedule Description],[Shift Pattern Description],[Mytime Description Code],[Type of Ticket],[Resolved?],[Date Submited],[Ticket Link])" _
& "Select " _
& "frm.[CSA Login]" & ", " _
& "frm.[Team Manager]" & ", " _
& "frm.[Schedule Description]" & ", " _
& "frm.[CSSM SPD]" & ", " _
& "frm.[Mytime Descrription]" & ", " _
& "frm.[Shift Pattern Descr]" & ", " _
& "frm.[MytimeDescriptionCode]" & ", " _
& "'Schedule Change'" & ", " _
& False & ", " _
& "Now()" & ", " _
& "route"
db.Execute sSQL
MsgBox ("Record saved.")
End Function
Any help is appreciated.
Try this:
sSQL = "Insert INTO T_Tickets ([CSA Login],[Team Manager],[Schedule Description],[WF Shift Pattern],[Mytime Schedule Description],[Shift Pattern Description],[Mytime Description Code],[Type of Ticket],[Resolved?],[Date Submited],[Ticket Link]) " _
& "Values (" _
& "'" & frm.[CSA Login] & "'," _
& "'" & frm.[Team Manager] & "'," _
& "'" & frm.[Schedule Description] & "'," _
& "'" & frm.[CSSM SPD] & "'," _
& "'" & frm.[Mytime Descrription] & "'," _
& "'" & frm.[Shift Pattern Descr] & "'," _
& "'" & frm.[MytimeDescriptionCode] & "'," _
& "'Schedule Change'," _
& " False, " _
& " Now(), " _
& "'" & route & "')"

Problems in HTA

So I'm trying to use ScriptGUI (from here) for my .bat files, but it doesn't have a file selector, so I attempted to add one.
I just copied and renamed some code around and it seems to work, apart from adding another variable for the subfunction thing.
' build a file selector
ElseIf UCase(strSplit(0)) = "FILE" Then
strHTML = strHTML & Build_File(strLabel,id,Replace(strLabel," ",""),strSplit(2))
' store the batch file in the arrControls array
arrControls(id) = "file,none"
id = id + 1
>
the problem seems to be the code under here "Click_File(" & fiId & "," & fiFilter & ")"
Function Build_File(fiLabel, fiId, fiName, fiFilter)
' Construct a file selector
Dim strHTML
strHTML = "<input class='button' type='button' name='" _
& fiName & "' value='" & fiLabel & "' id='" & fiId _
& "' onClick=" & chr(34) & "Click_File(" & fiId & "," & fiFilter & ")" & chr(34) _
& " onMouseOver=" & chr(34) & fiName & ".className='button btnhov'" & chr(34) _
& " onMouseOut=" & chr(34) & fiName & ".className='button'" & chr(34) _
& ">"
strHTML = strHTML & " <input type='text' readonly='readonly' value='none' name='fi" & fiName & "' id='fi" & fiId & "'/> "
Build_File = strHTML
End Function
>
Sub Click_File(strId, fiFilter)
' open a file selector
set objShell= CreateObject("WSCript.Shell")
myCur = objShell.CurrentDirectory
Dim file
file = GetFileName(myCur, fiFilter)
arrControls(strId) = "file," & file
document.getElementById("fi" & strId).value = file
document.getElementById("fi" & strId).size = Len(file) + 2
End Sub
It tells me I can't use parenthesis when calling a sub.
Any ideas?
EDIT: new problem,
I'm using a script from Rob van der Woude for the open file dialog (top post from here) which is apparently supposed to work in hta but I get an error saying "ActiveX component can't create object: 'UserAccounts.CommonDialog'"
Well, the message isn't wrong. You can't use parentheses when calling a Sub.
Change this line from:
& "' onClick=" & chr(34) & "Click_File(" & fiId & "," & fiFilter & ")" & chr(34) _
to:
& "' onClick=" & chr(34) & "Click_File " & fiId & "," & fiFilter & chr(34) _
and see if that solves your problem.

VB+Crystal report

I wrote this code but I got "Run time error '91':"
Private Sub Command1_Click()
Set rs = New ADODB.Recordset
openConnection
If Me.cmbMonth = "" And Me.cmbYear = "" Then
MsgBox "Please select MONTH and YEAR"
Exit Sub
End If
With crystalrpt
.ReportFileName = App.Path & "\Report\VariableReport.rpt" <-- ERROR IS HERE
.SelectionFormula = "{SW.dtaMonth}='" & cmbMonth.Text & "' and {SW.dtaYear}=" & dtaYear.Text & "" & _
" and {SFW.dtaMonth}='" & cmbMonth.Text & "' and {SFW.dtaYear}=" & dtaYear.Text & "" & _
" and {OT.dtaMonth}='" & cmbMonth.Text & "' and {OT.dtaYear}=" & dtaYear.Text & "" & _
" and {CL.dtaMonth}='" & cmbMonth.Text & "' and {CL.dtaYear}=" & dtaYear.Text & "" & _
" and {RM.dtaMonth}='" & cmbMonth.Text & "' and {RM.dtaYear}=" & dtaYear.Text & "" & _
" and {EL.dtaMonth}='" & cmbMonth.Text & "' and {EL.dtaYear}=" & dtaYear.Text & "" & _
" and {TRANS.dtaMonth}='" & cmbMonth.Text & "' and {TRANS.dtaYear}=" & dtaYear.Text & "" & _
" and {WD.dtaMonth}='" & cmbMonth.Text & "' and {WD.dtaYear}=" & dtaYear.Text & "" & _
" and {MP.dtaMonth}='" & cmbMonth.Text & "' and {MP.dtaYear}=" & dtaYear.Text & "" & _
" and {NONSTOCK.dtaMonth}='" & cmbMonth.Text & "' and {NONSTOCK.dtaYear}=" & dtaYear.Text & "" & _
" and {PACK.dtaMonth}='" & cmbMonth.Text & "' and {PACK.dtaYear}=" & dtaYear.Text & ""
.WindowTitle = "Report"
.Action = 1 'Will Show The Report
End With
End Sub
It's possible that you are trying to create an instance of a class (an object) from a class that is present on the machines you tested it on, but not on the machine it's been deployed to..... for example, I happen to know that I can make a VB program utilize a class for Nero Burning Rom.... I can make a nero object, and use it's methods and properties...... but that will only work on machines that have the Nero libraries installed. If it's not installed, when you try to make the object (either through early or late bindings with new or createobject), the variable that SHOULD refer to the object is still set to Nothing, because the library failed to create an instance of the requested class.....