JohnnyBQue
New Member
- Joined
- Apr 25, 2016
- Messages
- 8
I have a database with a "worksheet" (sheet5) named "Route Sheet"
In order to retrieve data from (sheet5) I have a column that acts like a "Primary Key" in access called "ID"
The ID column contain numbers in symmetrical order (0001, 0002, 0003, etc) for every row that contains data
I use the ID in a "form" that generates a "Route Sheet document" for material process based on the ID entered and corresponding data in the row
Now...I also use the "form" to enter information in the control fields then with a command button I then store the entered data to the "worksheet" (sheet5) named "Route Sheet" in the next empty row that's available.
in-lies the issue...when using the form to enter information i have no idea what the next available ID number is (so this control field is left blank) so when the data is stored in (sheet5) in the next empty row... the cell in the column named "ID" that's adjacent to the row of data just stored is now BLANK
upon the "store command" I need the cell in the column named "ID" that adjacent to the row of data just stored to have a new ID number based on incrementing the cell that is above it.
Below is the code I use to store the data and bring up the data in the "form" when a known ID is entered.
//
Private Sub cmdSend_Click()
'Dim the variables
Dim cNum As Integer
Dim X As Integer
Dim nextrow As Range
'change the number for the number of controls/text boxes on the userform
cNum = 17
Set nextrow = Sheet3.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0)
For X = 1 To cNum
nextrow = Me.Controls("Reg" & X).Value
Set nextrow = nextrow.Offset(0, 1)
Next
MsgBox "The data has been sent"
'Clear the controls boxes
cNum = 17
For X = 1 To cNum
Me.Controls("Reg" & X).Value = ""
Set nextrow = nextrow.Offset(0, 1)
Next
End Sub
Private Sub Reg1_AfterUpdate()
'Check to see if value exists
If WorksheetFunction.CountIf(Sheet3.Range("C:C"), Me.Reg1.Value) = 0 Then
MsgBox "This ID does not exist or has not been used"
Me.Reg1.Value = ""
Exit Sub
End If
'Lookup values based on first ID entered and place row/cell values into control boxes
With Me
.Reg2 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 2, 0)
.Reg3 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 3, 0)
.Reg4 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 4, 0)
.Reg5 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 5, 0)
.Reg6 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 6, 0)
.Reg7 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 7, 0)
.Reg8 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 8, 0)
.Reg9 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 9, 0)
.Reg10 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 10, 0)
.Reg11 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 11, 0)
.Reg12 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 12, 0)
.Reg13 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 13, 0)
.Reg14 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 14, 0)
.Reg15 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 15, 0)
.Reg16 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 16, 0)
.Reg17 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 17, 0)
End With
Sheet5.SReg2 = Reg2.Text
Sheet5.SReg3 = Reg3.Text
Sheet5.SReg4 = Reg4.Text
Sheet5.SReg5 = Reg5.Text
Sheet5.SReg6 = Reg6.Text
Sheet5.SReg7 = Reg7.Text
Sheet5.SReg8 = Reg8.Text
Sheet5.SReg9 = Reg9.Text
Sheet5.SReg10 = Reg10.Text
Sheet5.SReg11 = Reg11.Text
Sheet5.SReg12 = Reg12.Text
Sheet5.SReg13 = Reg13.Text
Sheet5.SReg14 = Reg14.Text
Sheet5.SReg15 = Reg15.Text
Sheet5.SReg16 = Reg16.Text
Sheet5.SReg17 = Reg17.Text
Sheet5.TSReg4 = Reg4.Text
Sheet5.TSReg12 = Reg12.Text
End Sub
//
In order to retrieve data from (sheet5) I have a column that acts like a "Primary Key" in access called "ID"
The ID column contain numbers in symmetrical order (0001, 0002, 0003, etc) for every row that contains data
I use the ID in a "form" that generates a "Route Sheet document" for material process based on the ID entered and corresponding data in the row
Now...I also use the "form" to enter information in the control fields then with a command button I then store the entered data to the "worksheet" (sheet5) named "Route Sheet" in the next empty row that's available.
in-lies the issue...when using the form to enter information i have no idea what the next available ID number is (so this control field is left blank) so when the data is stored in (sheet5) in the next empty row... the cell in the column named "ID" that's adjacent to the row of data just stored is now BLANK
upon the "store command" I need the cell in the column named "ID" that adjacent to the row of data just stored to have a new ID number based on incrementing the cell that is above it.
Below is the code I use to store the data and bring up the data in the "form" when a known ID is entered.
//
Private Sub cmdSend_Click()
'Dim the variables
Dim cNum As Integer
Dim X As Integer
Dim nextrow As Range
'change the number for the number of controls/text boxes on the userform
cNum = 17
Set nextrow = Sheet3.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0)
For X = 1 To cNum
nextrow = Me.Controls("Reg" & X).Value
Set nextrow = nextrow.Offset(0, 1)
Next
MsgBox "The data has been sent"
'Clear the controls boxes
cNum = 17
For X = 1 To cNum
Me.Controls("Reg" & X).Value = ""
Set nextrow = nextrow.Offset(0, 1)
Next
End Sub
Private Sub Reg1_AfterUpdate()
'Check to see if value exists
If WorksheetFunction.CountIf(Sheet3.Range("C:C"), Me.Reg1.Value) = 0 Then
MsgBox "This ID does not exist or has not been used"
Me.Reg1.Value = ""
Exit Sub
End If
'Lookup values based on first ID entered and place row/cell values into control boxes
With Me
.Reg2 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 2, 0)
.Reg3 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 3, 0)
.Reg4 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 4, 0)
.Reg5 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 5, 0)
.Reg6 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 6, 0)
.Reg7 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 7, 0)
.Reg8 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 8, 0)
.Reg9 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 9, 0)
.Reg10 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 10, 0)
.Reg11 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 11, 0)
.Reg12 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 12, 0)
.Reg13 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 13, 0)
.Reg14 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 14, 0)
.Reg15 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 15, 0)
.Reg16 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 16, 0)
.Reg17 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet3.Range("Lookup"), 17, 0)
End With
Sheet5.SReg2 = Reg2.Text
Sheet5.SReg3 = Reg3.Text
Sheet5.SReg4 = Reg4.Text
Sheet5.SReg5 = Reg5.Text
Sheet5.SReg6 = Reg6.Text
Sheet5.SReg7 = Reg7.Text
Sheet5.SReg8 = Reg8.Text
Sheet5.SReg9 = Reg9.Text
Sheet5.SReg10 = Reg10.Text
Sheet5.SReg11 = Reg11.Text
Sheet5.SReg12 = Reg12.Text
Sheet5.SReg13 = Reg13.Text
Sheet5.SReg14 = Reg14.Text
Sheet5.SReg15 = Reg15.Text
Sheet5.SReg16 = Reg16.Text
Sheet5.SReg17 = Reg17.Text
Sheet5.TSReg4 = Reg4.Text
Sheet5.TSReg12 = Reg12.Text
End Sub
//