Page 1 of 1

ดึงข้อมูลข้าม file แล้วให้มาแสดงที่ userform

Posted: Sat Oct 24, 2020 12:59 pm
by sooksun2009
รบกวนท่านอาจารย์ ผมต้องการ ดึงข้อมูลอีก file แล้วหาข้อมูลคอลั่มA จากfile database ถ้าข้อมูลตรงกับ textbox ให้ดึงข้อมูลที่คอลั่ม B มาแสดงที่ label ขอบคุณครับ

Re: ดึงข้อมูลข้าม file แล้วให้มาแสดงที่ userform

Posted: Sat Oct 24, 2020 7:54 pm
by snasui
:D กรุณาอธิบายเพิ่มเติมว่าใช้ไฟล์ไหนดึงข้อมูลจากไฟล์ไหน ด้วย Code ใน Form หรือ Module ใด Code ชื่อว่าอะไร ติดขัดบรรทัดใด จะได้เข้าถึงปัญหาได้โดยไวครับ

Re: ดึงข้อมูลข้าม file แล้วให้มาแสดงที่ userform

Posted: Sun Oct 25, 2020 6:13 pm
by sooksun2009
snasui wrote: Sat Oct 24, 2020 7:54 pm :D กรุณาอธิบายเพิ่มเติมว่าใช้ไฟล์ไหนดึงข้อมูลจากไฟล์ไหน ด้วย Code ใน Form หรือ Module ใด Code ชื่อว่าอะไร ติดขัดบรรทัดใด จะได้เข้าถึงปัญหาได้โดยไวครับ
ขอโทษทีครับ รีบมากเลยลืมแนบ code

Code: Select all

Private Sub CommandButton1_Click()
Dim wb As Workbook
Application.ScreenUpdating = False
    Application.DisplayAlerts = False
Set wb = Workbooks.Open("D:\Sooksun\Improvement\visual\Database.xlsm", False, False)
With wb
    Dim nRow As String
    nRow = wb.Sheets("Data").Columns(1).Find(txt_Vinno.Text).Row
     Sheet1.Activate
    If Err.Number = 91 Then
        txt_Vinno.RowSource = "txt_Vinno.Text"
          MsgBox "äÁèÁÕ¢éÍÁÙÅ Vin number"
          Exit Sub
    End If
     txt_Vinno = Cells(nRow, 1)
    lbl_model.Caption = Cells(nRow, 2)
    End With
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
End Sub
ความต้องการจาก file testpath ใน userform1 ป้อนข้อมูลที่ textbox txt_vinno แล้วกด button search ให้ไปดึงค่าที่ file database แล้วอยากได้ข้อมูลตามที่โพส

Re: ดึงข้อมูลข้าม file แล้วให้มาแสดงที่ userform

Posted: Tue Oct 27, 2020 9:11 pm
by snasui
:D ตัวอย่าง Code ครับ

Code: Select all

'Other code
Dim nRow As Integer
nRow = wb.Sheets("Data").Columns(1).Find(txt_Vinno.Text).Row
 Sheet1.Activate
If Err.Number = 91 Then
    txt_Vinno.RowSource = "txt_Vinno.Text"
      MsgBox "ไม่มีข้อมูล Vin number"
      Exit Sub
End If
UserForm1.lbl_model.Caption = wb.Sheets("Data").Cells(nRow, 2).Value
'Other code

Re: ดึงข้อมูลข้าม file แล้วให้มาแสดงที่ userform

Posted: Wed Nov 04, 2020 3:24 pm
by sooksun2009
snasui wrote: Tue Oct 27, 2020 9:11 pm :D ตัวอย่าง Code ครับ

Code: Select all

'Other code
Dim nRow As Integer
nRow = wb.Sheets("Data").Columns(1).Find(txt_Vinno.Text).Row
 Sheet1.Activate
If Err.Number = 91 Then
    txt_Vinno.RowSource = "txt_Vinno.Text"
      MsgBox "ไม่มีข้อมูล Vin number"
      Exit Sub
End If
UserForm1.lbl_model.Caption = wb.Sheets("Data").Cells(nRow, 2).Value
'Other code
ได้แล้วครับขอบคุณครับ