Advertisement

03.21.2005 at 01:58AM PST, ID: 21358277
[x]
Attachment Details

Problems with VB code created + date converted to american by accident when pasted from userform to spreadsheet

Asked by LozLaura17 in Microsoft Excel Spreadsheet Software

I have a spreadsheet that work fine but there are two problems.  

1.  is that the is a problem with a cell in my user form for the date.  If i type the date in a 13-Mar-2005 it will work fine. It will also work fine if i type in a date that is recent.  The problem arrises if i type the date as 13/03/2005 it will change it to 03/13/2005 when it is pasted from the userform into the spreadsheet.  It is not plausable for an imputter to have to always type the date in as 13-Mar-2005 but I am not sure what is wrong with my code to make it convert it to an american date. The code that i have used for this is.

Private Sub cmd_save_Click()
' This is used to move the record to the spreadsheet and
' create a new record
 'Commandbutton used to save the new record to the worksheet
lstRow = Worksheets("database").Range("c65536").End(xlUp).Row + 1
With Worksheets("database")
    .Range("c" & lstRow).Value = Me.frm_representative.txt_caseworker.Text
    .Range("d" & lstRow).Value = Me.frm_representative.txt_company.Text
    .Range("e" & lstRow).Value = Me.frm_reference.txt_referenceno1.Text
    .Range("f" & lstRow).Value = Me.frm_reference.txt_referenceno2.Text
    .Range("g" & lstRow).Value = Me.frm_post_type.cbo_post_type.Text
    .Range("h" & lstRow).Value = Me.frm_date.txt_receipt_date.Text
    .Range("j" & lstRow).Value = Me.frm_action_taken.cbo_action_taken.Text
   
    Me.frm_representative.txt_caseworker.Text = ""
    Me.frm_representative.txt_company.Text = ""
    Me.frm_reference.txt_referenceno1.Text = ""
    Me.frm_reference.txt_referenceno2.Text = ""
    Me.frm_post_type.cbo_post_type.Text = ""
    Me.frm_date.txt_receipt_date.Text = ""
    Me.frm_action_taken.cbo_action_taken.Text = ""
    MsgBox "Postal Record Entered Successfully"
   
End With
End Sub

My second problem is that i got help from here on a forward and back button but they do not seem to work properly.  I am sure that it is something that i have coded wrong but i seems to search from the bottom but when you go to look for other information that is the same it does not work properly

my code for this is

Search Button

Private Sub cmd_search_Click()
On Error GoTo dRecordNotFound
With Worksheets("Database")
    lstRow = Worksheets("Database").Range("C65536").End(xlUp).Row + 1
    Set Rng = .Range("F1:F" & lstRow).Find(Me.frm_reference.txt_referenceno2.Text)
   
    Me.frm_representative.txt_caseworker.Text = .Range("c" & Rng.Row).Value
    Me.frm_representative.txt_company.Text = .Range("d" & Rng.Row).Value
    Me.frm_reference.txt_referenceno1.Text = .Range("e" & Rng.Row).Value
    Me.frm_reference.txt_referenceno2.Text = .Range("f" & Rng.Row).Value
    Me.frm_post_type.cbo_post_type.Text = .Range("g" & Rng.Row).Value
    Me.frm_date.txt_receipt_date.Text = .Range("h" & Rng.Row).Value
    Me.frm_date.txt_receipt_date.Text = .Range("h" & Rng.Row).Value
    Me.frm_action_taken.cbo_action_taken.Text = .Range("j" & Rng.Row).Value
   
   
    Worksheets("Database").Activate
    Worksheets("Database").Range("c" & Rng.Row).Activate
   
End With
Exit Sub

dRecordNotFound:
    MsgBox "The record was not found"

On Error GoTo 0

End Sub

Next Button

rivate Sub cmd_next_Click()
With Worksheets("Database")
   lstRow = lstRow + 1
   If .Range("C" & lstRow).Value = "" Then
        MsgBox "You have reached the last record"
        Exit Sub
    End If
   
    Me.frm_representative.txt_caseworker.Text = .Range("c" & lstRow).Value
    Me.frm_representative.txt_company.Text = .Range("d" & lstRow).Value
    Me.frm_reference.txt_referenceno1.Text = .Range("e" & lstRow).Value
    Me.frm_reference.txt_referenceno2.Text = .Range("f" & lstRow).Value
    Me.frm_post_type.cbo_post_type.Text = .Range("g" & lstRow).Value
    Me.frm_date.txt_receipt_date.Text = .Range("h" & lstRow).Value
    Me.frm_date.txt_post_age.Text = .Range("h" & lstRow).Value
    Me.frm_action_taken.cbo_action_taken.Text = .Range("j" & lstRow).Value
 
   
End With
End Sub

Back Button

Private Sub cmd_back_Click()
With Worksheets("Database")
    lstRow = lstRow - 1
    If lstRow = 1 Then
       lstRow = 2
        Exit Sub
   End If
    Me.frm_representative.txt_caseworker.Text = .Range("c" & lstRow).Value
    Me.frm_representative.txt_company.Text = .Range("d" & lstRow).Value
    Me.frm_reference.txt_referenceno1.Text = .Range("e" & lstRow).Value
    Me.frm_reference.txt_referenceno2.Text = .Range("f" & lstRow).Value
    Me.frm_post_type.cbo_post_type.Text = .Range("g" & lstRow).Value
    Me.frm_date.txt_receipt_date.Text = .Range("h" & lstRow).Value
    Me.frm_date.txt_post_age.Text = .Range("i" & lstRow).Value
    Me.frm_action_taken.cbo_action_taken.Text = .Range("j" & lstRow).Value
End With
End Sub



 Start Free Trial
 
Loading Advertisement...
 
[+][-]03.21.2005 at 02:22AM PST, ID: 13589760

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Excel Spreadsheet Software
Sign Up Now!
Solution Provided By: SQL_Stu
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32