Getting error 20507 while launching Crystal Report 8 using VB6 - vb6

I received an old source code from the client and now he wants me to analyze and make it work again. I resolved 90% of the issues, but when I try to launch the crystal report, it shows me an error with not much information.
I am using VB6 with Crystal Report 8
This is the VB function where I am getting error
Private Sub cmdPrint_Click()
Screen.MousePointer = vbArrowHourglass
db.Execute ("Delete from TempReports")
db.Execute ("Delete from TempReports1")
With vsFlx
For I = 1 To .Rows - 1
db.Execute ("insert into TempReports (field1,field2,field3,field4,field5,field6,field7,field8, field19,field20,field14,field15,field16,field17,field18,field13,field21,field22) values ('" & .TextMatrix(I, 0) & "','" & .TextMatrix(I, 1) & "','" & .TextMatrix(I, 2) & "','" & .TextMatrix(I, 3) & "','" & .TextMatrix(I, 4) & "','" & .TextMatrix(I, 5) & "','" & .TextMatrix(I, 6) & "','" & .TextMatrix(I, 7) & "','" & MaskStartDate.Text & "','" & MaskEndDate.Text & "','" & fixquotes(lblItemGroup.Caption) & "','" & fixquotes(lblSubGroup.Caption) & "','" & fixquotes(lblSubsubGroup.Caption) & "','" & fixquotes(lblItemName.Caption) & "','" & fixquotes(lblMainItemName.Caption) & "'," & Val(txtBalanceQty) & ",'" & lblTotQtyIn.Caption & "','" & lblTotQtyOut.Caption & "') ")
Next
End With
With vsFlx2
For I = 1 To .Rows - 1
db.Execute ("insert into TempReports1 (field1,field2,field3,field4,field5,field6,field7,field8, field19,field20) values ('" & .TextMatrix(I, 0) & "','" & .TextMatrix(I, 1) & "','" & .TextMatrix(I, 2) & "','" & .TextMatrix(I, 3) & "','" & .TextMatrix(I, 4) & "','" & .TextMatrix(I, 5) & "','" & .TextMatrix(I, 6) & "','" & .TextMatrix(I, 7) & "','" & MaskStartDate.Text & "','" & MaskEndDate.Text & "') ")
Next
End With
crpt.ReportFileName = "reports\StockLedger.rpt"
crpt.SQLQuery = "Select * from TempReports order by id"
crpt.DiscardSavedData = True
crpt.WindowShowPrintSetupBtn = True
crpt.Action = 2
crpt.Destination = crptToWindow
Screen.MousePointer = vbDefault
End Sub
Getting error on this particular line
crpt.Action = 2
Screenshots for reference
any help is highly appreciated
UPDATE 1
I tried error handling and then I got following error message
UPDATE 2
Tried to register crpe32.dll and dwmapi.dll as suggest by craig but getting these errors

You are probably missing some dlls.
Do you have cpre23.dll and dwmapi.dll ?

I fixed this issue by reinstalling everything. I was running this project on Virtual Machine. So, reinstalling OS and everything fixed the issue.
I think I might messed up something by installing external dlls or replacing existing ones.

Related

Incorrect syntax near 'ID'

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
cn = New SqlConnection
cn.ConnectionString = "Data Source=LAPTOP-VLPOS8UG;Initial Catalog=FAMS;Integrated Security=True"
Try
cn.Open()
Dim query As String
query = "INSERT INTO Master (Asset ID, Asset Category, Department, Brand/Make, Product Serial No, Purchase Date, Purchase Order Date, Installation Date, Purchase Cost, Depriciation Rate, Vendor Code, Warranty Details, Processor, RAM, HDD, Operating System, Application/Software, Note, Asset Name, Status)" + "VALUES ('" & Asset_IDTextBox.Text & "','" & Asset_CategoryComboBox.Text & "','" & DepartmentComboBox.Text & "','" & Brand_MakeTextBox.Text & "','" & Product_Serial_NoTextBox.Text & "','" & Purchase_DateDateTimePicker.Text & "','" & Purchase_Order_DateDateTimePicker.Text & "','" & Installation_DateDateTimePicker.Text & "','" & Purchase_CostTextBox.Text & "','" & Depriciation_RateTextBox.Text & "','" & Vendor_CodeComboBox.Text & "','" & Warranty_DetailsComboBox.Text & "','" & ProcessorComboBox.Text & "','" & RAMComboBox.Text & "','" & HDDComboBox.Text & "','" & Operating_SystemComboBox.Text & "','" & Application_SodtwareTextBox.Text & "','" & NoteTextBox.Text & "','" & Asset_NameTextBox.Text & "','" & StatusComboBox.Text & "')"
cmd = New SqlCommand(query, cn)
dr = cmd.ExecuteReader
MessageBox.Show("Data Saved")
cn.Close()
Catch ex As SqlException
MessageBox.Show(ex.Message)
Finally
cn.Dispose()
End Try
End Sub
Since you tagged your question with ssms I suppose your RDBMS is SQL Server.
Your table has spaces in several column names; try using square brackets around column names that contain spaces:
query = "INSERT INTO Master ([Asset ID], [Asset Category],...

Access 2013 Insert / update

I have a form to add user.
I can add, delete rows in the table however I pretend to update if the user already exist.
My goal is press the row in sub form to edit.
but every time I press update it gives me an error.
Run-time error '3075' Syntax error operator in query expression.
the action code I have is this
Private Sub cmdAdd_Click()
'quando se carrega em Adicionar há 2 opcoes
'1-Insert
'2-Update
If Me.txtuserid.Tag & "" = "" Then
'1
CurrentDb.Execute "INSERT INTO user(userid, username, userfunction, usercc) " & _
" VALUES(" & Me.txtuserid & ",'" & Me.txtusername & "','" & Me.txtuserfun & "','" & Me.txtusercc & "')"
Else
'2
CurrentDb.Execute "UPDATE user " & _
" SET userid=" & Me.txtuserid & _
", username=" & Me.txtusername & "'" & _
", userfunction =" & Me.txtuserfun & "'" & _
", usercc =" & Me.txtusercc & "'" & _
" WHERE userid =" & Me.txtuserid.Tag
End If
'clear fields
cmdClear_Click
'refresh
SubForm1.Form.Requery
End Sub
What I'm doing wrong?
Did you miss ' in you update statement;
CurrentDb.Execute "UPDATE user " & _
" SET userid=" & Me.txtuserid & _
", username='" & Me.txtusername & "'" & _
", userfunction ='" & Me.txtuserfun & "'" & _
", usercc ='" & Me.txtusercc & "'" & _
" WHERE userid =" & Me.txtuserid.Tag

Number of query values and destination fields are not the same. Error Message

I'm having an error message with my codes in visual basic. Please help. Thanks.
The error says:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn
If Me.txtID.Tag & "" = "" Then
cmd.CommandText = "INSERT INTO ProfessorListTable(ID,LastName,FirstName,MI,Gender,Department,ContactNo,Address,EmailAddress,YearEmployed)" & _
" VALUES(" & Me.txtID.Text & ",'" & Me.txtLName.Text & "','" & _
Me.txtFName.Text & "','" & Me.txtMI.Text & "','" & _
Me.txtGender.Text & "','" & Me.txtDept.Text & "','" & _
Me.txtNo.Text & "','" & Me.txtAddress.Text & "','" & _
Me.txtEAdd.Text & "','" & Me.txtYear.Text & "',')"
cmd.ExecuteNonQuery()
Else
cmd.CommandText = "UPDATE ProfessorListTable " & _
" SET txtID=" & Me.txtID.Text & _
", LastName='" & Me.txtLName.Text & "'" & _
", FirstName='" & Me.txtFName.Text & "'" & _
", MI='" & Me.txtMI.Text & "'" & _
", Gender='" & Me.txtGender.Text & "'" & _
", Department='" & Me.txtDept.Text & "'" & _
", ContactNo='" & Me.txtNo.Text & _
", Address='" & Me.txtAddress.Text & "'" & _
", EmailAddress='" & Me.txtEAdd.Text & "'" & _
", YearEmployed='" & Me.txtYear.Text & _
" WHERE stdid=" & Me.txtID.Tag
cmd.ExecuteNonQuery()
End If
RefreshData()
End Sub
The
You had extra Comma (,) here
& Me.txtYear.Text & "','
So it's leads to 11 value instead of 10
And Address is reserved word so use it as [Address]
Try like this
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn
If Me.txtID.Tag & "" = "" Then
cmd.CommandText = "INSERT INTO ProfessorListTable(ID,LastName,FirstName,MI,Gender,Department,ContactNo,[Address],EmailAddress,YearEmployed)" & _
" VALUES(" & Me.txtID.Text & ",'" & Me.txtLName.Text & "','" & _
Me.txtFName.Text & "','" & Me.txtMI.Text & "','" & _
Me.txtGender.Text & "','" & Me.txtDept.Text & "','" & _
Me.txtNo.Text & "','" & Me.txtAddress.Text & "','" & _
Me.txtEAdd.Text & "','" & Me.txtYear.Text & "')"
cmd.ExecuteNonQuery()
Else
cmd.CommandText = "UPDATE ProfessorListTable " & _
" SET txtID=" & Me.txtID.Text & _
", LastName='" & Me.txtLName.Text & "'" & _
", FirstName='" & Me.txtFName.Text & "'" & _
", MI='" & Me.txtMI.Text & "'" & _
", Gender='" & Me.txtGender.Text & "'" & _
", Department='" & Me.txtDept.Text & "'" & _
", ContactNo='" & Me.txtNo.Text & _
", [Address]='" & Me.txtAddress.Text & "'" & _
", EmailAddress='" & Me.txtEAdd.Text & "'" & _
", YearEmployed='" & Me.txtYear.Text & _
" WHERE stdid=" & Me.txtID.Tag
cmd.ExecuteNonQuery()
End If
RefreshData()
End Sub

How to show text in combo box but referencing id field?

I wrote code for insert into and update table student_record_database having many foreign keys of other tables.
While running this code it is not accepting text data selected from combo box and giving error invalid number,integrity constraint,and DTpicker also not accepting given date though I have set custom format.
Here's my code below.I am having problem to show text in combo box.
<code>
Private Sub save_Click()
If Val(COMBO4) = 0 Then
SQL = "INSERT INTO STUDENT_RECORD_DATABASE(ROLLNO,FIRST_NAME,MIDDLE_NAME,LAST_NAME,CONTACT,CONTACT1,CONTACT2,ADDRESS,GRADE,DIVID,BLOOD_GROUP,HID,DATE_OF_BIRTH,TRANSPORT,SNAME,MEAL,BUSNO,RUTNO,DID,AID,CARD_TYPE,CARD_NO)"
SQL = SQL + "VALUES(" & Val(COMBO4) & ",'" & Trim(Text2) & "', '" & Trim(Text3) & "', '" & Trim(Text4) & "', " & Val(Text5) & ", " & Val(Text6) & ", " & Val(Text7) & ", '" & Trim(Text8) & "', '" & Trim(Combo1) & "','" & Val(Combo2) & "',"
SQL = SQL + " '" & Trim(Combo3) & "' ,'" & Val(Combo9) & "','" & DTPicker1.Value & "',"
SQL = SQL + " '" & Trim(Combo10) & "' ,'" & Combo5.Text & "' ,'" & Trim(Combo11) & "' ,'" & Combo6.Text & "' ,'" & Val(Combo12) & "' ,'" & Val(Combo7) & "','" & Val(Combo8) & "',"
SQL = SQL + " '" & Trim(Combo13) & "' ," & Text11.Text & " ) "
Set RES = CON.Execute(SQL)
MsgBox ("RECORD INSERTED")
Else
SQL = "UPDATE STUDENT_RECORD_DATABASE SET "
SQL = SQL + "ROLLNO= " & Val(COMBO4) & ","
SQL = SQL + "FIRST_NAME= '" & Trim(Text2) & "',"
SQL = SQL + "MIDDLE_NAME= '" & Trim(Text3) & "',"
SQL = SQL + "LAST_NAME= '" & Trim(Text4) & "',"
SQL = SQL + "CONTACT=" & Val(Text5) & ","
SQL = SQL + "CONTACT1=" & Val(Text6) & ","
SQL = SQL + "CONTACT2=" & Val(Text7) & ","
SQL = SQL + "ADDRESS= '" & Trim(Text8) & "',"
SQL = SQL + "GRADE='" & Trim(Combo1) & "',"
SQL = SQL + "DIVID='" & Val(Combo2) & "',"
SQL = SQL + "BLOOD_GROUP='" & Trim(Combo3) & "',"
SQL = SQL + "HID='" & Val(Combo9) & "',"
SQL = SQL + "DATE_OF_BIRTH=(' " & DateValue(DTPicker1.Value) & " ' ),"
SQL = SQL + "TRANSPORT='" & Trim(Combo10) & "',"
SQL = SQL + "SNAME='" & Trim(Combo5) & "',"
SQL = SQL + "MEAL='" & Trim(Combo11) & "',"
SQL = SQL + "BUSNO='" & Trim(Combo6) & "',"
SQL = SQL + "RUTNO=" & Val(Combo12) & ","
SQL = SQL + "DID='" & Val(Combo7) & "',"
SQL = SQL + "AID='" & Val(Combo8) & "',"
SQL = SQL + "CARD_TYPE='" & Trim(Combo13) & "',"
SQL = SQL + "CARD_NO=" & Val(Text11) & ""
SQL = SQL + "WHERE ROLLNO= " & Val(COMBO4) & ""
MsgBox ("RECORD UPDATED")
End If
End Sub
</code>
Error occurred is invalid month,integrity constraint-parent key not found,invalid number.
It's kinda hard to answer you question with no idea of the structure of STUDENT_RECORD_DATABASE and what you're updating but there are some things you could look at.
First, when inserting dates into Oracle like this you should use the TO_DATE() function on your date columns. I.e. DATE_OF_BIRTH
Next make sure that all foreign table key constraints are satisfied by your update.
There is no need to update ROLLNO if it is your primary key.
Finally make sure that none of the data you are trying to update is bigger that the size of string (E.g. VARCHAR2) columns. Also, some of these must surely be string columns and they are not bounded by quotes. E.g. CONTACT CONTACT1 CONTACT2 and CARD_NO
You need to use the combo box .ItemData property to store your value's ID field:
Do While Not myRecordset.EOF
myCombo.AddItem myRecordset("MyFieldString").Value
myCombo.ItemData(myCombo.NewIndex) = myRecordset("MyFieldID").Value
myRecordset.MoveNext
Loop
To refer to the selected combo value's .ItemData property:
"CARD_TYPE='" & Trim(Combo13.ItemData(Combo13.ListIndex)) & "',"
As for your data formatting issue, not sure about Oracle, but for SQL Server, you have to format the date value as such:
"DATE_OF_BIRTH=(' " & Format$(DTPicker1.Value, "yyyy-mm-dd") & " ' ),"

Runtime error 3704

In my vb6 I am getting error 3704 operation is not allowed when object is closed.
I have search stackoverflow for similar problem but I think I'm missing something. I need to update every row in vfp based from recordset rs1 Here my code:
Option Explicit
Dim cn As New ADODB.Connection
Dim cn1 As New ADODB.Connection
Private Sub trns_Click()
Set cn = New ADODB.Connection
Set cn1 = New ADODB.Connection
cn.ConnectionString = MDI1.txtcn.Text
cn.Open
cn1.ConnectionString = "Provider=VFPOLEDB;Data Source=\\host1\software\MIL\company0"
cn1.Open
rs1.Open "Select * from trans", cn, adOpenStatic, adLockPessimistic
Do While Not rs2.EOF
rs2.Open "update transac set no_ot_1_5 = " & rs1.Fields("ovt1") & ", no_ot_2_0 = " & rs1.Fields("ovt2") & ", no_ot_3_0" _
& "= " & rs1.Fields("ovt3") & ",Meal_allw = " & rs1.Fields("meal_allow") & ",on_duty = " & rs1.Fields("cnt") & ",no_d_local = " & rs1.Fields("local") & ",no_d_sick" _
& "= " & rs1.Fields("sick") & ",no_d_abs = " & rs1.Fields("absence") & ",no_d_spc = " & rs1.Fields("special") & ",Revenue02" _
& "= " & rs1.Fields("refund") & ",Revenue05 = " & rs1.Fields("prepay") & ",Deduct05 = " & rs1.Fields("prepay") & ",Revenue01 = " & rs1.Fields("comm") & "where code = '" & rs1.Fields("emp_code") & "' and transac.date = CTOD('" & trans.txtend2 & "')", cn1, adOpenDynamic, adLockPessimistic
If Not rs2.EOF Then
rs2.MoveNext
End If
Loop
rs2.close
Update query doesn't return recordset, hence your rs2 is not opened.
You perform your loop on the wrong recordeset : I replaced the some of the rs2 with rs1 in your code.
Do While Not rs1.EOF
rs2.Open "update transac set no_ot_1_5 = " & rs1.Fields("ovt1") & ", no_ot_2_0 = " & rs1.Fields("ovt2") & ", no_ot_3_0" _
& "= " & rs1.Fields("ovt3") & ",Meal_allw = " & rs1.Fields("meal_allow") & ",on_duty = " & rs1.Fields("cnt") & ",no_d_local = " & rs1.Fields("local") & ",no_d_sick" _
& "= " & rs1.Fields("sick") & ",no_d_abs = " & rs1.Fields("absence") & ",no_d_spc = " & rs1.Fields("special") & ",Revenue02" _
& "= " & rs1.Fields("refund") & ",Revenue05 = " & rs1.Fields("prepay") & ",Deduct05 = " & rs1.Fields("prepay") & ",Revenue01 = " & rs1.Fields("comm") & "where code = '" & rs1.Fields("emp_code") & "' and transac.date = CTOD('" & trans.txtend2 & "')", cn1, adOpenDynamic, adLockPessimistic
If Not rs1.EOF Then
rs1.MoveNext
End If
Loop
rs1.close
You dont need to create a recordset to execute an update, insert or delete on the database. Just use the statement cn1.Execute YourSqlStatement where YourSqlStatement is the string you are passing on the rs2.Open instruction. The Execute method on the connection optionally accepts a byRef variable where you can get the number of records affected.
Example:
Dim nRecords As Integer
cn1.Execute "Update Table Set Field = Value Where AnotherField = SomeValue ", nRecords
MsgBox "Total Updated Records: " & Format(nRecords,"0")
try to open your rs2 before using if in the do while statement., or do it like this
rs2.open " blah blah blah "
Do Until rs2.eof
For Each fld In rs2.field
value_holder = fld.value
Next
rs2.movenext
Loop

Resources