Consulting

Results 1 to 3 of 3

Thread: help for homework

  1. #1

    help for homework

    hello, I need some help. I am facing 1 error. Is there anyone who can fix this for me? It only takes a few minutes. thank you so much
    Private Sub cmdAddrecord_Click()
    Dim wks1, wks2 As Worksheet
    Dim AddNewl, AddNew2 As Range
    Set wksl = sheet1
    Set wks2 = sheet2
    (error)   Set AddNew1 = wks1.Range("A65356").End(x1Up).Offset(1, 0)
    AddNew1.Offset(0, 0).Value = txthastaid.Text
    AddNew1.Offset(0, 1).Value = cboTitle.Text
    AddNew1.Offset(0, 2).Value = txtname.Text
    AddNew1.Offset(0, 3).Value = txtsurname.Text
    AddNew1.Offset(0, 4).Value = txttell.Text
    AddNew1.Offset(0, 5).Value = txtage.Text
    AddNew1.Offset(0, 6).Value = cboGender.Text
    AddNew1.Offset(0, 7).Value = txtadress.Text
    AddNew1.Offset(0, 8).Value = txtcounty.Text
    AddNew1.Offset(0, 9).Value = txtpostacode.Text
    lstAppointment.ColumnCount = 10
    lstAppointment.RowSource = "B1:J65356"
    Set AddNew2 = wks2.Range("A65356").End(x1Up).Offset(1, 0)
    AddNew2.Offset(0, 0).Value = txtdoctorid.Text
    AddNew2.Offset(0, 1).Value = cboDocTitle.Text
    AddNew2.Offset(0, 2).Value = txtdname.Text
    AddNew2.Offset(0, 3).Value = txtdsurname.Text
    AddNew2.Offset(0, 4).Value = txttell.Text
    AddNew2.Offset(0, 5).Value = txtdp.Text
    AddNew2.Offset(0, 6).Value = txtdp2.Text
    AddNew2.Offset(0, 7).Value = txtdp3.Text
    AddNew2.Offset(0, 8).Value = txtemail.Text
    AddNew2.Offset(0, 9).Value = txtAppointment.Text
    AddNew2.Offset(0, 10).Value = txtdate.Text
    AddNew2.Offset(0, 11).Value = txttime.Text
    AddNew2.Offset(0, 12).Value = cboConfirm.Text
    lstdisplay.ColumnCount = 12
    lstdisplay.RowSource = "B1:L65356"
    Attached Files Attached Files

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Looks like it might have gotten some unexpected characters into some of the lines (cut and paste maybe)

    I added Option Explicit and retyped the lines

    Option Explicit
    
    Dim ThisDay As Date
    Dim ThisYear, ThisMth As Date
    Dim CreateCal As Boolean
    Dim i As Integer
    
    
    Private Sub CB_Mth_Change()
    Build_Calendar
    End Sub
    Private Sub CB_Yr_Change()
    Build_Calendar
    End Sub
    
    
    Private Sub cmdAddrecord_Click()
        Dim wks1 As Worksheet, wks2 As Worksheet
        Dim AddNew1 As Range, AddNew2 As Range
        
        Set wks1 = sheet1
        Set wks2 = sheet2
        
        Set AddNew1 = wks1.Range("A65356").End(xlUp).Offset(1, 0)
        
        AddNew1.Offset(0, 0).Value = txthastaid.Text
        AddNew1.Offset(0, 1).Value = cboTitle.Text
        AddNew1.Offset(0, 2).Value = txtname.Text
        AddNew1.Offset(0, 3).Value = txtsurname.Text
        AddNew1.Offset(0, 4).Value = txttell.Text
        AddNew1.Offset(0, 5).Value = txtage.Text
        AddNew1.Offset(0, 6).Value = cboGender.Text
        AddNew1.Offset(0, 7).Value = txtadress.Text
        AddNew1.Offset(0, 8).Value = txtcounty.Text
        AddNew1.Offset(0, 9).Value = txtpostacode.Text
        
        lstAppointment.ColumnCount = 10
        
        lstAppointment.RowSource = "B1:J65356"
        
        
        
        Set AddNew2 = wks2.Range("A65356").End(xlUp).Offset(1, 0)
        
        AddNew2.Offset(0, 0).Value = txtdoctorid.Text
        AddNew2.Offset(0, 1).Value = cboDocTitle.Text
        AddNew2.Offset(0, 2).Value = txtdname.Text
        AddNew2.Offset(0, 3).Value = txtdsurname.Text
        AddNew2.Offset(0, 4).Value = txttell.Text
        AddNew2.Offset(0, 5).Value = txtdp.Text
        AddNew2.Offset(0, 6).Value = txtdp2.Text
        AddNew2.Offset(0, 7).Value = txtdp3.Text
        AddNew2.Offset(0, 8).Value = txtemail.Text
        AddNew2.Offset(0, 9).Value = txtAppointment.Text
        AddNew2.Offset(0, 10).Value = txtdate.Text
        AddNew2.Offset(0, 11).Value = txttime.Text
        AddNew2.Offset(0, 12).Value = cboConfirm.Text
        
        lstdisplay.ColumnCount = 12
        lstdisplay.RowSource = "B1:L65356"
        
    End Sub
    

    By the way, in this ...

    Dim wks1, wks2 As Worksheet Dim AddNew1, AddNew2 As Range

    … wks1 and AddNew1 are Variants, not what you were expecting


    With VBA each variable you Dim needs the specific type, UNLESS you really do want Variants. I just Dim everything explicitly

        Dim wks1 As Worksheet, wks2 As Worksheet
        Dim AddNew1 As Range, AddNew2 As Range
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Thank you very much I am grateful to you. i love you







Posting Permissions

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