+ Reply to Thread
Results 1 to 4 of 4

Thread: Excel and VBA form

  1. #1
    Registered User
    Join Date
    04-20-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    24

    Excel and VBA form

    Hi All,

    I have created a form and it is working fine. Here is my form

    Private Sub cmdAdd_Click()
    Dim iRow As Long
    Dim iAction As Long
    Dim iPriority As Long
    Dim ws As Worksheet
    Set ws = Worksheets("PlanningActions")
    
    'find first empty row in database
    iRow = ws.Cells(Rows.Count, 1) _
    .End(xlUp).Offset(1, 0).Row
    
    
    If Trim(Me.txtAction.Value) = "" Then
    Me.txtAction.SetFocus
    MsgBox "Please enter an Action"
    Exit Sub
    End If
    
    'copy the data to the database
    ws.Cells(iRow, 1).Value = Me.txtAction.Value
    ws.Cells(iRow, 2).Value = Me.txtTopic.Value
    ws.Cells(iRow, 3).Value = Me.txtPerson.Value
    ws.Cells(iRow, 4).Value = Me.txtLocation.Value
    ws.Cells(iRow, 5).Value = Me.txtDate.Value
    ws.Cells(iRow, 6).Value = Me.txtContact.Value
    ws.Cells(iRow, 7).Value = Me.cboPriority.Value
    ws.Cells(iRow, 8).Value = Me.cboPriority.List(iPriority, 1)
    
    
    
    'clear the data
    Me.txtAction.Value = ""
    Me.txtTopic.Value = ""
    Me.txtPerson.Value = ""
    Me.txtLocation.Value = ""
    Me.txtDate.Value = ""
    Me.txtContact.Value = ""
    Me.cboPriority.Value = ""
    
    Me.txtAction.SetFocus
    
    End Sub
    
    
    Private Sub cmdClose_Click()
    Unload Me
    End Sub
    
    
    
    
    Private Sub UserForm_QueryClose(Cancel As Integer, _
    CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
    Cancel = True
    MsgBox "Please use the button!"
    End If
    End Sub
    
    Private Sub UserForm_Initialize()
    Dim cPri As Range
    Dim cLoc As Range
    Dim ws As Worksheet
    Set ws = Worksheets("LookupLists")
    
    For Each cPri In ws.Range("Priority")
    With Me.cboPriority
    .AddItem cPri.Value
    .List(.ListCount - 1, 0) = cPri.Offset(0, 1).Value
    End With
    Next cPri
    
    
    
    Me.txtAction.Value = ""
    Me.txtTopic.Value = ""
    Me.txtPerson.Value = ""
    Me.txtLocation.Value = ""
    Me.txtDate.Value = ""
    Me.txtContact.Value = ""
    Me.cboPriority.Value = ""
    Me.txtAction.SetFocus
    
    
    End Sub

    In my excelsheet already unique ID's of the person has been entered. when the data is entered through this form it should search that particular ID and infront of that data to be entered.

    How do i do that?
    Last edited by pike; 04-26-2011 at 05:35 AM. Reason: add code tags

  2. #2
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,155

    Re: Excel and VBA form

    Hi Mythri Hegde
    Roy has a good example on searching with a userform

    J & R Database Form...
    http://www.excel-it.com/vba_examples.htm

    hope it helps or will get you started
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

  3. #3
    Registered User
    Join Date
    04-20-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Excel and VBA form

    Hi Pike,

    I will go try to find the solution over there.

    Thannks

  4. #4
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,155

    Re: Excel and VBA form

    Hi Mythri Hegde
    Have a look at the code, you will see you may have to add a search button. it a good example and all the works been done. Post back if you have any problems
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0