Question: - Prepare a userform where the input fields are o Book Name ( text ) o Book Author ( text ) o ISBN No (
Prepare a userform where the input fields are
o Book Name text
o Book Author text
o ISBN No unique number
o Selling Price Currency between $ and $
o Last Months Sales Quantity integer between and
In the form there should be Save Data, Close Form buttons. Each record should be added to a new line.
Prepare a second form reachable from the first form where
o there are summarizing fields where you calculate the total monthly revenue total quantity sold best selling books title revenue of best selling book to total sales
o You can display the details of a book when you enter the ISBN no so there will be a field where you enter ISBN no and when you click it it should display all the details about that book
Fill with at least book data you can randomly give numbers and names...Private Sub CommandButtonClick
Dim iRow As Long
Dim ws As Worksheet
Set ws WorksheetsSheet Ensure sheet name matches exactly, including case
Find first empty row in database
iRow wsCells.FindWhat: SearchOrder:xlRows, SearchDirection:xlPrevious, LookIn:xlValuesRow
Check for a book name assuming TextBox is for book name
If TrimMeTextBoxValue Then
MeTextBoxSetFocus
MsgBox "Please enter a Book Name"
Exit Sub
End If
Check for ISBN number assuming TextBox is for ISBN
If TrimMeTextBoxValue Then
MeTextBoxSetFocus
MsgBox "Please enter an ISBN Number"
Exit Sub
End If
Check if ISBN already exists
If WorksheetFunction.CountIfwsRangeC:C MeTextBoxValue Then
MeTextBoxSetFocus
MsgBox "ISBN already exists!"
Exit Sub
End If
Copy the data to the database
With ws
CellsiRowValue MeTextBoxValue Book Name
CellsiRowValue MeTextBoxValue Book Author
CellsiRowValue MeTextBoxValue ISBN
Validate and assign Selling Price
If IsNumericMeTextBoxValue And ValMeTextBoxValue And ValMeTextBoxValue Then
CellsiRowValue MeTextBoxValue
Else
MsgBox "Selling Price must be between $ and $
MeTextBoxSetFocus
Exit Sub
End If
Validate and assign Last Month's Sales Quantity
If IsNumericMeTextBoxValue And ValMeTextBoxValue And ValMeTextBoxValue Then
CellsiRowValue MeTextBoxValue
Else
MsgBox "Sales Quantity must be between and
MeTextBoxSetFocus
Exit Sub
End If
wbSave
End With
Clear the data
MeTextBoxValue
MeTextBoxValue
MeTextBoxValue
MeTextBoxValue
MeTextBoxValue
MsgBox "Data saved successfully!"
End Sub
Private Sub CommandButtonClick
Unload Me
End Sub
Private Sub TextBoxEnter
MsgBox "Price Between $ $
End Sub
Private Sub TextBoxEnter
MsgBox "Quantity Between
End Sub we write the vba code like this but it give "error on excel. can you tell me what the mistake is and rewrite the code. Note: textbox refers the textcode in our code
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
