| |

VerySource

 Forgot password?
 Register
Search
View: 974|Reply: 8

A depressed problem with the ADO control, ask the old bird for pointers

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-18 19:30:02
| Show all posts |Read mode
The connection string of the ADO control is attached after the form is started
 For Each ctl In frm.Controls
        If TypeOf ctl Is Adodc Then
            ctl.ConnectionString = MstrConn
            ctl.Tag = MsName $&"|"&MiIndex%
            'Store control array information
            If MsFiter $ <> "" Then ctl.RecordSource = ctl.RecordSource&"where"&MsFiter $
            ctl.Refresh
        End If
    Next

The code has been no problem now. Depressed. The ADO control is loaded earlier than the form. The startup will prompt [Microsoft] [ODBC Driver Manager] No data source name was found and no default driver was specified.
Then call my code to assign the string and then it displays normally


It can be seen that the ADO control is already loaded before the form start event.

Assignment of ConnectionString ... I can't always connect an empty library so that the ADO control does not report an error?

How do I block this tip
Reply

Use magic Report

1

Threads

21

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 Great Britain

Post time: 2020-6-24 18:00:01
| Show all posts
Can you put this in the form active sub?
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-6-25 03:45:01
| Show all posts
Not for that reason, it is because the ADO control is initialized before any event of the form
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-9 14:15:01
| Show all posts
Form_Initialize

Write code in this event
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-8-20 22:30:01
| Show all posts
Every time you encounter this situation, the ADO control has already helped the database.

That is how do I replace the ADO help database string, replace it before Form_Initialize,
In other words, when the ADO control is initialized, can I control it?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-20 23:30:01
| Show all posts
Doesn’t it work without Ado binding? Write directly in code, convenient and fast.
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-8-21 07:15:01
| Show all posts
:'<
Too many controls...too lazy to change one by one... Does anyone know the way?
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-21 08:45:02
| Show all posts
The way to save the country by curve:
1) Delete all "ConnectionString" and "RecordSource" of ADO on the screen-modify it to connect with code;
2) Maintain the binding of the control and ADO unchanged;
3) Add code similar to the following (where "XXX001" is your database connection string):
Option Explicit

Private m_strAdoConn As String

Private m_blnInitOK As Boolean


'' Form_Load()
Private Sub Form_Load()
    m_blnInitOK = False
   
    m_strAdoConn = "XXX001"
End Sub


'' Form_Activate()
Private Sub Form_Activate()
    If m_blnInitOK Then Exit Sub'' Do not call it again
   
    m_blnInitOK = True
   
    Adodc1.ConnectionString = m_strAdoConn
    Adodc1.RecordSource = "T_USER"
    Adodc1.Refresh
End Sub


************************************************** ******************
The above code has just been debugged on my computer. If you need it, you can leave an email and send it to you.
In fact, the principle is very simple: the database connection and settings are performed only in "Form_Activate()".
************************************************** ******************
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-21 09:00:01
| Show all posts
My code format has changed (the code should have TAB spaces), understand it yourself!

The role of "Adodc1.Refresh" is to force a connection to the database again.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list