Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB hangs

Status
Not open for further replies.

gurukrishna

Programmer
Jun 3, 2001
8
IN
Hi all!! I seem to have a small problem. I am using ADODB programming in order to insert records into a table in Oracle. I open a recordset,get all the info from the text fields, do the rs.Fields(index)=txtBox etc etc and then rs.Update. When the system comes to this statement, VB hangs!!. I use the same connection string in other forms (ofcourse after changing the data source name etc etc)..and it works there without a problem. But in this form it gives a problem.Can neone help please?? thanx.
 
I have 2 forms one called frmCompanyDetails and frmCompanyDetails2.When I say rs1.Update in the first form VB hangs.


the code is given below..

form1 code
Private rs1 As New ADODB.Recordset
Private con As New ADODB.Connection

Private Sub commandNext_Click()

If txtName.Text = "" Then
rvalue = MsgBox("Enter a Name: ", vbApplicationModal + vbInformation + vbCritical, "Correction")
Exit Sub
End If

If IsDate(txtDOS.Text) Then
hello = 1
Else
rvalue = MsgBox("Enter a valid date.", vbApplicationModal + vbCritical + vbOKOnly, "Correction")
Exit Sub
End If

If txtAddress.Text = "" Then
rvalue = MsgBox("Enter a value for Address: ", vbApplicationModal + vbInformation + vbCritical, "Correction")
Exit Sub
End If

If txtProjects.Text = "" Then
rvalue = MsgBox("Enter a value Projects: ", vbApplicationModal + vbInformation + vbCritical, "Correction")
Exit Sub
End If

If txtWeb.Text = "" Then
rvalue = MsgBox("Enter a value for Web Address: ", vbApplicationModal + vbInformation + vbCritical, "Correction")
Exit Sub
End If

If txtHead.Text = "" Then
rvalue = MsgBox("Enter a value for Head Office Address: ", vbApplicationModal + vbInformation + vbCritical, "Correction")
Exit Sub
End If

If txtHR.Text = "" Then
rvalue = MsgBox("Enter a H R Name: ", vbApplicationModal + vbInformation + vbCritical, "Correction")
Exit Sub
End If

If txtPhone.Text = "" Then
rvalue = MsgBox("Enter a value for Phone Number : ", vbApplicationModal + vbInformation + vbCritical, "Correction")
Exit Sub
End If







rs1.AddNew


rs1.Fields(0) = txtName.Text
rs1.Fields(1) = txtAddress.Text
rs1.Fields(2) = txtProjects.Text
rs1.Fields(3) = txtDOS.Text
rs1.Fields(4) = txtWeb.Text
rs1.Fields(5) = txtHead.Text
rs1.Fields(6) = txtHR.Text
rs1.Fields(7) = " "
rs1.Fields(8) = txtPhone.Text
rs1.Fields(9) = txtEmail.Text

rs1.Update
rs1.Close

frmCompanyDetails.Hide
frmCompanyDetails2.Show


End Sub

Private Sub Form_Load()
With con
.Open " Provider=MSDAORA.1;User ID=6csa2-20;PASSWORD=sem;Data Source=orcl"

End With

With rs1
.ActiveConnection = con
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = "company"
.Open
End With





txtName.Text = ""
txtAddress.Text = ""
txtProjects.Text = ""
'txtDOS.Text = ""
txtWeb.Text = ""
txtHead.Text = ""
txtHR.Text = ""

txtPhone.Text = ""
txtEmail = ""
End Sub



form2 code
Dim con1 As New ADODB.Connection
Dim rs1 As New ADODB.Recordset





Private Sub cmdAdd_Click()
If Combo1.Text = "Select Course Name" Then
rvalue = MsgBox("Please Select a course name ", vbApplicationModal + vbInformation + vbCritical, "Correction")
Exit Sub
End If

If Combo2.Text = "Select Branch Name" Then
rvalue = MsgBox("Please select a branch name ", vbApplicationModal + vbInformation + vbCritical, "Correction")
Exit Sub
End If

rs1.Fields(0) = frmCompanyDetails.txtName.Text
rs1.Fields(1) = Combo1.Text
rs1.Fields(2) = Combo2.Text

Me.Hide
Exit Sub

End Sub

Private Sub Form_Load()
With con
.Open " Provider=MSDAORA.1;User ID=6csa2-20;PASSWORD=sem;Data Source=orcl"

End With

With rs1
.ActiveConnection = con1
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = "branches"
.Open
End With


End Sub
Private Sub Combo1_Click()
If Combo1.Text = "BE" Then
Combo2.Visible = True
Combo2.Clear
Combo2.Text = "Select Branch Name"
Combo2.AddItem ("Computer Science")
Combo2.AddItem ("Electrical and Electronics")
Combo2.AddItem ("Electronics and Communication")
Combo2.AddItem ("Information Science")
Combo2.AddItem ("Mechanical")
Combo2.AddItem ("Medical Electronics")
Combo2.AddItem ("Instrumentation")
Combo2.AddItem ("Civil")
Combo2.AddItem ("Architecture")
Combo2.AddItem ("Telecommunication")
Combo2.AddItem ("IEM")
Combo2.AddItem ("Chemical")
End If
If Combo1.Text = "MBA" Then
Combo2.Clear
Combo2.Text = "Select Branch Name"
Combo2.Visible = True
Combo2.AddItem ("Systems")
Combo2.AddItem ("Marketing")
Combo2.AddItem ("Finance")
Combo2.AddItem ("HR")
End If
If Combo1.Text = "MTech" Then
Combo2.Clear
Combo2.Text = "Select Branch Name"
Combo2.Visible = True
Combo2.AddItem ("Civil")
Combo2.AddItem ("Computer Science")
Combo2.AddItem ("Mechanical")
End If
If Combo1.Text = "MCA" Then
Combo2.Visible = False
flag = 1
End If



End Sub
 
The MSDORA driver does not support the rs.update. Try the following connection string in your Form_Load():

With con
.Open "driver={MICROSOFT ODBC FOR ORACLE};" & _
"server=orcl;" & _
"uid=6csa2-20;pwd=sem"
End With
 
thanx woyler!! but.. I use the same connection string in several other forms and it works perfectly there..why?
 
Are you using the AddNew and Update methods of the recordset?
 
yes I am... and if I had to send the results of a query to a person by e-mail how can I integrate VB and Outlook? I read a FAQ on this forum but was of little help.
 
As far as the recordset question, Are you stepping through the code when it hangs or are you running compiled?

For the email question you have to first create a new class, and make a reference to the Microsoft Outlook object library. Next add the following code:

Option Explicit

'Local Error Variables
Private mlErrorNumber As Long
Private msErrorSource As String
Private msErrorDescription As String

Private oOutLookApp As Outlook.Application
Private oMailItem As MailItem

'Public Properties
Public MsgReceiptRequested As Boolean
Public Importance As OlImportance
Public FlagStatus As OlFlagStatus

Public msSubject As String


'*******************************************************************************************
'Purpose: Add Recipient to Recipient List
'Inputs: Recipient Name
'Outputs: True if SuccessFul, Otherwise False
'*******************************************************************************************
Public Sub AddRecipient(Recipient As String)

On Error GoTo ErrorHandler

oMailItem.Recipients.Add Recipient

Exit Sub

ErrorHandler:
Err.Raise Err.Number, Err.Source, Err.Description
End Sub


Public Function EMailSend(psMessage As String) As Boolean
On Error GoTo ErrorHandler

With oMailItem
.FlagStatus = FlagStatus
.Importance = Importance
.ReadReceiptRequested = MsgReceiptRequested
.Subject = msSubject
.Body = psMessage
.Send
End With

EMailSend = True
Exit Function

ErrorHandler:
EMailSend = False
Err.Raise Err.Number, Err.Source, Err.Description
End Function

'****************************************************************
'Purpose: To Return the Class Error Number to the Client
'****************************************************************
Public Property Get ErrorNumber() As Long
ErrorNumber = mlErrorNumber
End Property

'***************************************************************
'Purpose: To Return the Class Error Source to the Client
'***************************************************************
Public Property Get ErrorSource() As String
ErrorSource = msErrorSource
End Property

'********************************************************************
'Purpose: To Return the Class Error Description to the Client
'********************************************************************
Public Property Get ErrorDescription() As String
ErrorDescription = msErrorDescription
End Property

Public Property Get Subject() As String
Subject = msSubject
End Property

Public Property Let Subject(ByVal psSubject As String)
msSubject = psSubject
End Property



Private Sub Class_Initialize()
Set oOutLookApp = New Outlook.Application
Set oMailItem = oOutLookApp.CreateItem(olMailItem)
End Sub
 
thanx!! for the mail info, but if I want to send the results of a query from my table to somebody from VB then how would that fit into this code?
As for the recordset,in order to figure out where it was hanging, I did step through the code and it hung there ie at the rs.update. that's how I figured that it was hanging there..

If I wanted to integrate eduora or some other mail client with VB would that be possible?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top