research15
New Member
- Joined
- May 20, 2021
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
I would be grateful for any help with the following problem. I have built a userform to help with inputting data for a research project due to the number of variables involved and to allow for comparison of data at the time of input. By following guides I have built a form that works well and exports to the database using IF, iRow and visible commands to make things work smoothly with a listbox showing key columns from the database.
The final part that would make data input much easier is the ability to go back and modify records.
This is the code for writing to the `database` sheet:
This is my attempt at coding for recalling the data for modification:
This was trying to use the selected row within my listbox to set the row to be recalled. I am only trying with a section of database first before I expand to all the data.
From my understanding if I can get the data to populate my userform, I could then modify and this would overwrite the database upon clicking save keeping the same row number.
Any help would be greatly appreciated. I have found several videos and guides to how to recall information and the complexity seems to vary wildly and I've tried with very limited success.
Many thanks
The final part that would make data input much easier is the ability to go back and modify records.
This is the code for writing to the `database` sheet:
Code:
Sub Submit()
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Database")
iRow = [Counta(Database!A:A)] + 1
With sh
.Cells(iRow, 1) = iRow - 1
.Cells(iRow, 2) = frmFORM.txtTrialID.Value
.Cells(iRow, 3) = IIf(frmFORM.chkcomplete.Value = True, "Complete", "Incomplete")
.Cells(iRow, 4) = IIf(frmFORM.chkhistcomp.Value = True, "Complete", "Incomplete")
.Cells(iRow, 5) = IIf(frmFORM.chkCFsurgcomp.Value = True, "Complete", "Incomplete")
.Cells(iRow, 6) = IIf(frmFORM.chkCFSurg2Comp.Value = True, "Complete", "Incomplete")
.Cells(iRow, 7) = IIf(frmFORM.chkCFPathComp.Value = True, "Complete", "Incomplete")
.Cells(iRow, 8) = IIf(frmFORM.chkXRComp.Value = True, "Complete", "Incomplete")
.Cells(iRow, 9) = IIf(frmFORM.chkcomplete.Value = True And frmFORM.chkhistcomp.Value = True And frmFORM.chkCFsurgcomp.Value = True And frmFORM.chkCFSurg2Comp.Value = True And frmFORM.chkCFPathComp.Value = True And frmFORM.chkXRComp.Value = True, "Complete", "Incomplete")
End With
End Sub
This is my attempt at coding for recalling the data for modification:
VBA Code:
Sub Modify()
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Database")
iRow = lstDatabase.ActiveCell
frmFORM.txtDateSurg.Value = Sheets("Database").Cells(iRow, 10).Value
frmFORM.txtAge.Value = Sheets("Database").Cells(iRow, 11).Value
End Sub
This was trying to use the selected row within my listbox to set the row to be recalled. I am only trying with a section of database first before I expand to all the data.
From my understanding if I can get the data to populate my userform, I could then modify and this would overwrite the database upon clicking save keeping the same row number.
Any help would be greatly appreciated. I have found several videos and guides to how to recall information and the complexity seems to vary wildly and I've tried with very limited success.
Many thanks