PDA

View Full Version : transfer 2 forms to spreadhsheet



Emoncada
12-27-2007, 10:10 AM
I have this code I am trying to work on

Sub InsertEm()
Dim RowNext As Integer, i As Long, j As Long
'last row of data
RowNext = Worksheets("Packing Slip Pim").Cells(Rows.Count, 1).End(xlUp).Row
'Count number of items
For i = 1 To 18
If Me.Controls("CmbBoxDesc" & i).Text <> "" Then
j = j + 1
Else
Exit For
End If
Next

For i = 1 To j
With Worksheets("Packing Slip Pim")
.Cells(RowNext + i, 1) = UCase(TxtOrdNum.Value)
.Cells(RowNext + i, 2) = TxtShipDate.Text
.Cells(RowNext + i, 3) = LblShipVia.Caption
.Cells(RowNext + i, 4) = UCase(Me.Controls("TxtTrack" & i).Value)
.Cells(RowNext + i, 5) = Me.Controls("TxtSN" & i).Value
.Cells(RowNext + i, 6) = Me.Controls("CmbBoxDesc" & i).Value
.Cells(RowNext + i, 7) = Me.Controls("TxtQua" & i).Value
.Cells(RowNext + i, 8) = CmbBoxProject.Value
.Cells(RowNext + i, 9) = LblRacf.Caption
.Cells(RowNext + i, 10) = CmbBoxClientName.Value
.Cells(RowNext + i, 11) = CmbBoxLocation.Value
.Cells(RowNext + i, 12) = TxtShippedBy.Text
.Cells(RowNext + i, 13) = TxtComments.Text
If Me.ChkBoxComments = True Then .Cells(RowNext + i, 14) = "YES"
If Me.ChkBoxNewHire = True Then .Cells(RowNext + i, 15) = "YES"
End With
Next
If UserForm2.CmbBoxDesc1.Value <> "" Then
For i = 1 To j
With UserForm2
With Worksheets("Packing Slip Pim")
.Cells(RowNext + i, 1) = UCase(TxtOrdNum.Value)
.Cells(RowNext + i, 2) = TxtShipDate.Text
.Cells(RowNext + i, 3) = LblShipVia.Caption
.Cells(RowNext + i, 4) = UCase(Me.Controls("TxtTrack" & i).Value)
.Cells(RowNext + i, 5) = Me.Controls("TxtSN" & i).Value
.Cells(RowNext + i, 6) = Me.Controls("CmbBoxDesc" & i).Value
.Cells(RowNext + i, 7) = Me.Controls("TxtQua" & i).Value
.Cells(RowNext + i, 8) = CmbBoxProject.Value
.Cells(RowNext + i, 9) = LblRacf.Caption
.Cells(RowNext + i, 10) = CmbBoxClientName.Value
.Cells(RowNext + i, 11) = CmbBoxLocation.Value
.Cells(RowNext + i, 12) = TxtShippedBy.Text
.Cells(RowNext + i, 13) = TxtComments.Text
If Me.ChkBoxComments = True Then .Cells(RowNext + i, 14) = "YES"
If Me.ChkBoxNewHire = True Then .Cells(RowNext + i, 15) = "YES"
End With
End With
Next

Basically want to call this when the save button is clicked via Userform1 or UserForm2 and then Possibly a UserForm3.

I am trying to test if there is a value in Userform2.CmbDesc1 Then for it to transfer all the data on that form to the spreadsheet the same way it does with Userform1.

I tried somethings but it's not working. Any Help would be great.

Bob Phillips
12-27-2007, 10:16 AM
It is not clear how the forms are related, how they are invoked, where this code is located. To help we need more information to understand the situation.

Emoncada
12-27-2007, 10:21 AM
Ok I have Userform1 that has (cmbBoxDesc1 through CmbBoxDesc18) That are Description of products. Now If there are more than 18 Products that need to be entered i created a UserForm2 (which is a duplicate of UserForm1 just blank) and then they can enter more products. Now I want when they click The CmdSavePrint Button It Sends everything on UserForm1 to the Spreadsheet (<-- This part works already) *and Test to see if Userform2 have anything in "CmbBoxDesc1" if so then for it to send all the data from Userform2 to the spreadsheet also. *Right after Userform1.

Emoncada
12-27-2007, 10:31 AM
This is the entire code for that cmdbutton
Private Sub CmdPrintSave_Click()
Dim mpLookup As String
Dim mpRange As Range
Dim mpCell As Range
Dim mpFirst As String
Dim mpFind As Long

mpLookup = Me.TxtOrdNum.Text
On Error Resume Next
mpFind = Application.Match(mpLookup, Worksheets("Packing Slip Pim").Columns(1), 0)
On Error GoTo 0
If mpFind = 0 Then

InsertEm
Else

If MsgBox("A Match has been found do you wish do delete previous one(s)?", _
vbYesNo) = vbYes Then

With Worksheets("Packing Slip Pim").Columns(1)

Set mpCell = .Find(mpLookup)
Set mpRange = mpCell
mpFirst = mpRange.Address

Do

Set mpCell = .FindNext(mpCell)
If Not mpCell Is Nothing Then

Set mpRange = Union(mpRange, mpCell)
End If
Loop Until mpCell Is Nothing Or mpCell.Address = mpFirst
End With
InsertEm
If Not mpRange Is Nothing Then mpRange.EntireRow.Delete
End If
End If
End Sub

Sub InsertEm()
Dim RowNext As Integer, i As Long, j As Long
'last row of data
RowNext = Worksheets("Packing Slip Pim").Cells(Rows.Count, 1).End(xlUp).Row
'Count number of items
For i = 1 To 18
If Me.Controls("CmbBoxDesc" & i).Text <> "" Then
j = j + 1
Else
Exit For
End If
Next

For i = 1 To j
With Worksheets("Packing Slip Pim")
.Cells(RowNext + i, 1) = UCase(TxtOrdNum.Value)
.Cells(RowNext + i, 2) = TxtShipDate.Text
.Cells(RowNext + i, 3) = LblShipVia.Caption
.Cells(RowNext + i, 4) = UCase(Me.Controls("TxtTrack" & i).Value)
.Cells(RowNext + i, 5) = Me.Controls("TxtSN" & i).Value
.Cells(RowNext + i, 6) = Me.Controls("CmbBoxDesc" & i).Value
.Cells(RowNext + i, 7) = Me.Controls("TxtQua" & i).Value
.Cells(RowNext + i, 8) = CmbBoxProject.Value
.Cells(RowNext + i, 9) = LblRacf.Caption
.Cells(RowNext + i, 10) = CmbBoxClientName.Value
.Cells(RowNext + i, 11) = CmbBoxLocation.Value
.Cells(RowNext + i, 12) = TxtShippedBy.Text
.Cells(RowNext + i, 13) = TxtComments.Text
If Me.ChkBoxComments = True Then .Cells(RowNext + i, 14) = "YES"
If Me.ChkBoxNewHire = True Then .Cells(RowNext + i, 15) = "YES"
End With
Next
For i = 1 To 18
If UserForm2.Controls("CmbBoxDec" & i).Text <> "" Then
j = j + 1
Else
Exit For
End If

Next

For i = 1 To j
With UserForm2
With Worksheets("Packing Slip Pim")
.Cells(RowNext + i, 1) = UCase(TxtOrdNum.Value)
.Cells(RowNext + i, 2) = TxtShipDate.Text
.Cells(RowNext + i, 3) = LblShipVia.Caption
.Cells(RowNext + i, 4) = UCase(Me.Controls("TxtTrack" & i).Value)
.Cells(RowNext + i, 5) = Me.Controls("TxtSN" & i).Value
.Cells(RowNext + i, 6) = Me.Controls("CmbBoxDesc" & i).Value
.Cells(RowNext + i, 7) = Me.Controls("TxtQua" & i).Value
.Cells(RowNext + i, 8) = CmbBoxProject.Value
.Cells(RowNext + i, 9) = LblRacf.Caption
.Cells(RowNext + i, 10) = CmbBoxClientName.Value
.Cells(RowNext + i, 11) = CmbBoxLocation.Value
.Cells(RowNext + i, 12) = TxtShippedBy.Text
.Cells(RowNext + i, 13) = TxtComments.Text
If Me.ChkBoxComments = True Then .Cells(RowNext + i, 14) = "YES"
If Me.ChkBoxNewHire = True Then .Cells(RowNext + i, 15) = "YES"
End With
End With
Next

Now I caught another issue.
I have it test Column A if there is a duplicate order now i believe it would prompt the MsgBox when sending Userform2.

Help! XLD

Emoncada
12-27-2007, 02:31 PM
Hope I explained it better.

Emoncada
12-28-2007, 07:45 AM
This is the spreadsheet.

I was able to get it print ok but when it transfers the data to the spreadsheet for some reason it transfers an extra line from UserForm2.

Any help would be great!

The Txt files needs to go into the C: Drive