Click here to Skip to main content
15,914,016 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionResource limits?? Pin
Austin Jones16-Jul-01 11:15
Austin Jones16-Jul-01 11:15 
GeneralVB COM Testing Pin
amitrgholap16-Jul-01 1:09
amitrgholap16-Jul-01 1:09 
GeneralDAO Pin
sripriyaunni15-Jul-01 20:08
sripriyaunni15-Jul-01 20:08 
GeneralRe: DAO Pin
Fariborz4-Aug-01 6:22
Fariborz4-Aug-01 6:22 
Generalstart options of MS IE5.5 Pin
9-Jul-01 7:20
suss9-Jul-01 7:20 
GeneralRe: start options of MS IE5.5 Pin
9-Jul-01 11:07
suss9-Jul-01 11:07 
GeneralExcel formulae Pin
Ian5-Jul-01 20:38
Ian5-Jul-01 20:38 
Generalright click and refresh Pin
Ian3-Jul-01 22:55
Ian3-Jul-01 22:55 
Hi,

I am using input boxes to enter data into a spreadsheet. But my problem is that if the user makes an error then they can't go back. This is partly because after the user has input the data my code puts their data into variable and then does various calculations with it before putting the result into defined cells.
Does anyone know how I could put in a user update if they right click the cell where they have made an error? The new data would then have to be refrshed through the rest of the code. Heres an example of some of the code

Private Sub Workbook_Open()



Dim mydate As Date
Dim baldate As Date
Dim duedate As Date
Dim todate As Date
Dim TheDate As Date ' Declare variables.
Dim Msg
Dim hey
Dim Ms
Dim instal
Dim instmon
Dim mon

mydate = Date
ActiveSheet.Cells(15, 1).Value = mydate

rentac = Application.InputBox(Prompt:="Enter rent account number", Default:="1234567", Type:=1)
tenant = Application.InputBox(Prompt:="Enter name of tenant", Default:="Tenant", Type:=2)
adda = Application.InputBox(Prompt:="Enter house no and street, eg 1 Walnut Street", Default:="1 Walnut Street", Type:=2)
addb = Application.InputBox(Prompt:="Enter name of Town, eg Prudhoe", Default:="Prudhoe", Type:=2)
AddEx = Application.InputBox(Prompt:="Enter additional address lines, eg Hexham", Default:="Prudhoe", Type:=2)
addc = Application.InputBox(Prompt:="Enter name of County, eg Northumberland", Default:="Northumberland", Type:=2)
addd = Application.InputBox(Prompt:="Enter postcode, eg NE42 123", Default:="NE42 123")



bal = Application.InputBox(Prompt:="Enter opening balance", Default:="100.0", Type:=1)
baldate = Application.InputBox(Prompt:="Enter date at which balance applies", Default:="17-06-01", Type:=1)
duedate = Application.InputBox(Prompt:="Enter first charge date eg usually Monday coming ", Default:="18-06-01", Type:=1)
todate = Application.InputBox(Prompt:="Enter last charge date if different from end of year ", Default:="31-03-02", Type:=1)
rent = Application.InputBox(Prompt:="Enter weekly rent", Default:="45.00", Type:=1)


ActiveSheet.Cells(13, 1).Value = "Ref" & rentac

ActiveSheet.Cells(81, 2).Value = rentac

ActiveSheet.Cells(17, 1).Value = "Dear " & tenant

ActiveSheet.Cells(51, 1).Value = tenant
ActiveSheet.Cells(52, 1).Value = adda
ActiveSheet.Cells(53, 1).Value = addb
ActiveSheet.Cells(54, 1).Value = AddEx
ActiveSheet.Cells(55, 1).Value = addc
ActiveSheet.Cells(56, 1).Value = addd

ActiveSheet.Cells(25, 2).Value = baldate
ActiveSheet.Cells(25, 8).Value = bal
ActiveSheet.Cells(27, 2).Value = duedate
ActiveSheet.Cells(27, 4).Value = todate
ActiveSheet.Cells(27, 7).Value = rent


fred = DateDiff("w", duedate, todate)
ActiveSheet.Cells(27, 5).Value = fred + 1

eric = DateDiff("m", duedate, todate)
'ActiveSheet.Cells(27, 9).Value = eric + 1

Dim boolCanExit As Boolean

Do
boolCanExit = True ' will always exit unless the user enters incorrect value
freq = Application.InputBox(Prompt:="Would you like the standing order paid monthly or weekly?", Default:="monthly", Type:=2)

TheDate = Date
Msg = DatePart("m", TheDate) ' Msg now equals the number current month number


dayDate = Date
Ms = DatePart("d", dayDate) 'Ms now equals the current day number




If freq = "monthly" Then
If Ms >= 8 Then
eric = eric - 1
End If
'the annual charge
wop = ActiveSheet.Cells(29, 8).Value
'the annual charge divided by how many periods are left
jazz = wop / (eric + 1)
'the rounded figure
ollie = (Round(jazz, 2) + 0.01)


'the two multiplied together which gets you within pennies of the right fig
thomas = ollie * (eric + 1)

remfig = (thomas - wop) 'the odd fig

dick = ollie - remfig

ActiveSheet.Cells(31, 1).Value = "Less 1 payment @"
ActiveSheet.Cells(31, 2).Value = dick
ActiveSheet.Cells(32, 1).Value = (("Less " & eric) & " payments @")
ActiveSheet.Cells(32, 2).Value = ollie
ActiveSheet.Cells(32, 8).Value = eric * ollie


'this bit sets the payment date code



If Ms >= 8 Then

Msg = Msg + 1
End If
instal = 15 & "th "

If Msg = 1 Then
mon = "January"
End If

If Msg = 2 Then
mon = "February"
End If

If Msg = 3 Then
mon = "March"
End If

If Msg = 4 Then
mon = "April"
End If

If Msg = 5 Then
mon = "May"
End If

If Msg = 6 Then
mon = "June"
End If

If Msg = 7 Then
mon = "July"
End If

If Msg = 8 Then
mon = "August"
End If

If Msg = 9 Then
mon = "September"
End If

If Msg = 10 Then
mon = "October"
End If

If Msg = 11 Then
mon = "November"
End If

If Msg = 12 Then
mon = "December"
End If



ActiveSheet.Cells(87, 3).Value = instal & mon
Msg = Msg + 1
If Msg = 1 Then
mon = "January"
End If

If Msg = 2 Then
mon = "February"
End If

If Msg = 3 Then
mon = "March"
End If

If Msg = 4 Then
mon = "April"
End If

If Msg = 5 Then
mon = "May"
End If

If Msg = 6 Then
mon = "June"
End If

If Msg = 7 Then
mon = "July"
End If

If Msg = 8 Then
mon = "August"
End If

If Msg = 9 Then
mon = "September"
End If

If Msg = 10 Then
mon = "October"
End If

If Msg = 11 Then
mon = "November"
End If

If Msg = 12 Then
mon = "December"
End If
ActiveSheet.Cells(88, 3).Value = instal & mon
ActiveSheet.Cells(88, 4).Value = "monthly"
ActiveSheet.Cells(89, 3).Value = "15-03-02"


Else
If freq = "weekly" Then


Dim i As Integer
Dim datTemp As Date

For i = 1 To 7
datTemp = DateAdd("d", i, Date)
If Weekday(datTemp) = vbMonday Then

ActiveSheet.Cells(87, 3).Value = datTemp

ActiveSheet.Cells(88, 4).Value = "weekly"
ActiveSheet.Cells(89, 3).Value = "25-03-02"

'MsgBox "Next Monday will be " & datTemp
End If
Next
Dim datnex As Date
Dim dated As Date
dated = datTemp
For i = 1 To 7
datnex = DateAdd("d", i, dated)
If Weekday(datnex) = vbMonday Then
ActiveSheet.Cells(88, 3).Value = datnex

'MsgBox "Next Monday will be " & datnex

End If
Next






Dim derrick
derrick = DateDiff("w", datTemp, todate)


'ActiveSheet.Cells(31, 2).Value = (ActiveSheet.Cells(29, 8).Value) / (derrick + 1)
' ActiveSheet.Cells(31, 1).Value = (("Less " & derrick + 1) & " payments @")
'ActiveSheet.Cells(31, 8).Value = (ActiveSheet.Cells(31, 2).Value) * (derrick + 1)

'the annual charge
wop = ActiveSheet.Cells(29, 8).Value
'the annual charge divided by how many periods are left
jazz = wop / (derrick + 1)
'the rounded figure
ollie = (Round(jazz, 2) + 0.01)

'the two multiplied together which gets you within pennies of the right fig
thomas = ollie * (derrick + 1)

remfig = (thomas - wop) 'the odd fig

dick = ollie - remfig

ActiveSheet.Cells(31, 1).Value = "Less 1 payment @"
ActiveSheet.Cells(31, 2).Value = dick
ActiveSheet.Cells(32, 1).Value = (("Less " & derrick) & " payments @")
ActiveSheet.Cells(32, 2).Value = ollie
ActiveSheet.Cells(32, 8).Value = derrick * ollie





Else: MsgBox "Error you have not entered a relevant frequency Please enter monthly or weekly"
boolCanExit = False

End If
End If
Loop Until boolCanExit = True


End Sub


Many thanks

Generalmail attach Pin
3-Jul-01 13:37
suss3-Jul-01 13:37 
GeneralCode Editor for VB Pin
James Stigler3-Jul-01 12:11
James Stigler3-Jul-01 12:11 
GeneralRe: Code Editor for VB Pin
CodeCrafty®17-Jul-01 22:13
CodeCrafty®17-Jul-01 22:13 
GeneralGet selected row from a DBGrid control Pin
Ameenudeen2-Jul-01 14:51
Ameenudeen2-Jul-01 14:51 
GeneralPages in tif Image Pin
28-Jun-01 0:28
suss28-Jun-01 0:28 
Generalpivot table Pin
tamar yona27-Jun-01 20:07
tamar yona27-Jun-01 20:07 
GeneralEvents with an MTS COM object. Pin
Jamie Nordmeyer27-Jun-01 6:01
Jamie Nordmeyer27-Jun-01 6:01 
GeneralRe: Events with an MTS COM object. Pin
Klaus Probst7-Aug-01 15:49
Klaus Probst7-Aug-01 15:49 
QuestionHow can i use the UDP in the Web ?? Pin
khamis22-Jun-01 7:49
khamis22-Jun-01 7:49 
AnswerRe: How can i use the UDP in the Web ?? Pin
Klaus Probst7-Aug-01 15:51
Klaus Probst7-Aug-01 15:51 
GeneralShowing modeless form in VB DLLs called from MFC Pin
22-Jun-01 1:18
suss22-Jun-01 1:18 
GeneralFormatting duplicates in excel Pin
Ian21-Jun-01 23:16
Ian21-Jun-01 23:16 
GeneralString Pin
20-Jun-01 4:46
suss20-Jun-01 4:46 
GeneralRe: String Pin
20-Jun-01 16:00
suss20-Jun-01 16:00 
GeneralRe: String Pin
Michael P Butler20-Jun-01 22:35
Michael P Butler20-Jun-01 22:35 
GeneralRe: String Pin
19-Jul-01 10:07
suss19-Jul-01 10:07 
Generalcomunication Pin
19-Jun-01 6:28
suss19-Jun-01 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.