VB 6.0 - Adodc1 Control Not Refreshing - VB6 - Asked By Eric Smith on 25-Sep-08 11:53 AM

Heres my problem.  I have a form name frmOwner and the user uses this to search for various information about a company. On the current record the user wants to view EDI setup information so they select an option from a menu and another form is displayed (frmMapping).  frmMapping takes the data from frmOwner.txtOwnerID.text and popluates an Adodc1 control, that is used to populate a datagrid (dgResults).  This works fine, but my problem is when I close the frmMapping and go back to frmOwner and go to another record and want to view EDI setup information the datagrid on frmOwner still displays the previous record EDI information, so I have close the form and open it again to display the new record EDI's information.

I have attached the code for the frmMapping, any thoughs on how to correct this behavior.  Thanks


Sub FillAdodcControl()
    Adodc1.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=WITCO;Data Source=SQLDEV2"
    Adodc1.RecordSource = "select EDI10200.EDIMPID, EDI10200.OwnerID, EDI10200.VendorID, EDI10200.Channel, EDI10200.IsProduction, EDI10200.StartsOn, EDI10200.EndsOn, PM00200.VendName FROM EDI10200 left join PM00200 on PM00200.VendorID = EDI10200.VendorID where EDI10200.OwnerID='" & frmOwner.txtOwnerID.Text & "'"
    Adodc1.Refresh
    Set dgResults.DataSource = Adodc1
End Sub

Private Sub cmdClose_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    Call FillAdodcControl
    Call FormatGrid
End Sub

'===============================================================================================
'used to format the datagrid on form frmEDIWorksheet
'this fixed the issues aftter updates,deletes and inserts the datagrid would lose its format
'===============================================================================================
Sub FormatGrid()
    dgResults.Columns.Item(0).Width = 750   'EMPID
    dgResults.Columns.Item(1).Width = 900   'OwnerID
    dgResults.Columns.Item(2).Width = 900   'VendorID
    dgResults.Columns.Item(3).Width = 675   'Channel
    dgResults.Columns.Item(4).Width = 1000  'IsProduction
    dgResults.Columns.Item(5).Width = 1000  'StartsOn
    dgResults.Columns.Item(6).Width = 1000  'EndOn
    dgResults.Columns.Item(7).Width = 3500  'VendName
   
    'Variable for Format
    Dim stdYesNo As StdFormat.StdDataFormat
   
    'DataGridFormat
    Set stdYesNo = New StdFormat.StdDataFormat
    stdYesNo.Type = fmtBoolean
    stdYesNo.TrueValue = "YES" 'display value for True ( -1)
    stdYesNo.FalseValue = "NO" 'display value for False (0)
   
    Set dgResults.Columns(4).DataFormat = stdYesNo
End Sub

'=================================================================================================
'= When user clicks datagrid display the record in the fields (current record section)
'=================================================================================================
Private Sub dgResults_SelChange(Cancel As Integer)
    dgResults.SelStart = 1
    'lblEDIMPID.Caption = dgResults.Columns(0).Text 'not being displayed
    lblOwnerID.Caption = dgResults.Columns(1).Text
    txtVendorID.Text = dgResults.Columns(2).Text
    txtChannel.Text = dgResults.Columns(3).Text
    Dim chkIsProduct As Integer
    chkIsProduct = dgResults.Columns(4).Value
   
    If chkIsProduct = 0 And chkIsProduct <> 2 Then
       chkIsProduction.Value = 0 'unchecked
    Else
        chkIsProduction.Value = 1 'checked
    End If
   
    dtpStartsOn.Value = dgResults.Columns(5).Text
    dtpEndsOn.Value = dgResults.Columns(6).Text
End Sub

force to refresh - Perry replied to Eric Smith on 25-Sep-08 12:06 PM

Try to do Form.Refresh() which will force the complete form to be refreshed.

-Paresh

Refresh method of adodc control - Perry replied to Eric Smith on 25-Sep-08 12:07 PM

The usual cause of this error is that your SQL Server only accepts Windows authentication and not SQL Server authentication.  It's either you also enable SQL Server authentication, which can be done using Enterprise Manager, or you use trusted connection.

For the different values of a connection string, you can refer to the following website:

http://www.connectionstrings.com/

refresh database - Perry replied to Eric Smith on 25-Sep-08 12:10 PM

What you should probably do is check to see if you're running from the IDE and then set the ADODC
ConnectionString to the respective database *in* code. Both the ConnectionString and Recordsource
properties of the ADODC should be blank at runtime:

Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My
Documents\db1.mdb;Persist Security Info=False"
Adodc1.RecordSource = "Table1"
Adodc1.Refresh

***Put some delay here***

Determine if running in IDE:

http://support.microsoft.com/default.aspx?scid=KB;EN-US;q177636&

refresh - sundar k replied to Eric Smith on 26-Sep-08 03:46 AM

Can you give a messsage box in your form_load event to check whether your frmmapping form is loading second time properly, the problem of your frmOwner.txtOwnerID.Text not being set properly second time when the frmmapping is invoked can be because your form is already loaded into memory and and its only being showed up in the screen when the user clicks the menu item.

Private Sub Form_Load()
    msgbox "entering form_load"
    Call FillAdodcControl
    Call FormatGrid
End Sub