code problem

d0wnt0wn

Well-known Member
Joined
Oct 28, 2002
Messages
771
hi ... I have made a user form that adds to a list in my database..... form works great except for one thing..... there are two input boxes one for materials and one for price... it is set so if i enter a price and not a material then click add a msg appears telling me to enter a material..... but i also want to do the opposite.... if i enter a material and not a price i need a msg box to appear saying i need to insert a price... any help on this would be great

Private Sub CMDADD_click()
Dim irow As Long
Dim ws As Worksheet
Set ws = Worksheets("LISTS")

'find first empty row in database
irow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'check for material
If Trim(Me.TXTMAT.Value) = "" Then
Me.TXTMAT.SetFocus
MsgBox "Please Enter a Material"


Exit Sub

End If

'copy the data to the database
ws.Cells(irow, 1).Value = Me.TXTMAT.Value
ws.Cells(irow, 2).Value = Me.TXTPRICE.Value

'clear the data
Me.TXTMAT.Value = ""
Me.TXTPRICE.Value = ""
Me.TXTMAT.SetFocus
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You can try this I think this should do what you are looking for.

Private Sub CMDADD_click()
Dim irow As Long
Dim ws As Worksheet
Set ws = Worksheets("LISTS")

'find first empty row in database
irow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'check for material
If Trim(Me.TXTMAT.Value) = "" Then
Me.TXTMAT.SetFocus
MsgBox "Please Enter a Material"


Exit Sub

End If

'check for Price
If Trim(Me.TXTPRICE.Value) = "" Then
Me.TXTPRICE.SetFocus
MsgBox "Please Enter a Price"
Exit Sub
End If

'copy the data to the database
ws.Cells(irow, 1).Value = Me.TXTMAT.Value
ws.Cells(irow, 2).Value = Me.TXTPRICE.Value

'clear the data
Me.TXTMAT.Value = ""
Me.TXTPRICE.Value = ""
Me.TXTMAT.SetFocus
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top