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 $5.00 and $100.00)
o Last Months Sales Quantity (integer between 100 and 1500)
- 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 10 book data (you can randomly give numbers and names...)Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")' Ensure sheet name matches exactly, including case
' Find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row +1
' Check for a book name (assuming TextBox1 is for book name)
If Trim(Me.TextBox1.Value)="" Then
Me.TextBox1.SetFocus
MsgBox "Please enter a Book Name"
Exit Sub
End If
' Check for ISBN number (assuming TextBox3 is for ISBN)
If Trim(Me.TextBox3.Value)="" Then
Me.TextBox3.SetFocus
MsgBox "Please enter an ISBN Number"
Exit Sub
End If
' Check if ISBN already exists
If WorksheetFunction.CountIf(ws.Range("C:C"), Me.TextBox3.Value)>0 Then
Me.TextBox3.SetFocus
MsgBox "ISBN already exists!"
Exit Sub
End If
' Copy the data to the database
With ws
.Cells(iRow,1).Value = Me.TextBox1.Value ' Book Name
.Cells(iRow,2).Value = Me.TextBox6.Value ' Book Author
.Cells(iRow,3).Value = Me.TextBox3.Value ' ISBN
' Validate and assign Selling Price
If IsNumeric(Me.TextBox4.Value) And Val(Me.TextBox4.Value)>=5 And Val(Me.TextBox4.Value)<=100 Then
.Cells(iRow,4).Value = Me.TextBox4.Value
Else
MsgBox "Selling Price must be between $5 and $100"
Me.TextBox4.SetFocus
Exit Sub
End If
' Validate and assign Last Month's Sales Quantity
If IsNumeric(Me.TextBox5.Value) And Val(Me.TextBox5.Value)>=100 And Val(Me.TextBox5.Value)<=1500 Then
.Cells(iRow,5).Value = Me.TextBox5.Value
Else
MsgBox "Sales Quantity must be between 100 and 1500"
Me.TextBox5.SetFocus
Exit Sub
End If
wb.Save
End With
' Clear the data
Me.TextBox1.Value =""
Me.TextBox6.Value =""
Me.TextBox3.Value =""
Me.TextBox4.Value =""
Me.TextBox5.Value =""
MsgBox "Data saved successfully!"
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub TextBox4_Enter()
MsgBox "Price Between $5- $100"
End Sub
Private Sub TextBox5_Enter()
MsgBox "Quantity Between 100-1500"
End Sub we write the vba code like this but it give "error 91" on excel. can you tell me what the mistake is and rewrite the code. Note: textbox6 refers the textcode2 in our code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!