Subform and calculation HELP

ian_ok

Registered User.
Local time
Today, 18:51
Joined
May 1, 2001
Messages
90
My database is a flight booking system (USING Access2000):

I have a form that has 2 subforms the form displays the flight data along with 1 subform for the main passenger, address, numberoftickets (required) and total cost the other subform is for any additional passengers travelling with main passenger.

Q1
How do I get subform 2 to only allow the a specific number of entries for that passenger
i.e. Ian want 2 tickets so Ian is main and 1 additional passenger so I want subform 2 to allow only 1 entry for passenger Ian

Q2
I want the main form to update and show the ticketsavailable (minus) the numberoftickets (required) and an error message if numberoftickets (required) is more than ticketsavailable.


This is my current code which isn’t working!!!

Private Sub numbeoftickets_AfterUpdate()
If [numberoftickets] > [Forms]![Frmbookflight]![Numberofseats] Then 'I'VE GOT THIS TO WORK NOW with amended code'

MsgBox "error"
Else

totalcost = [numbeoftickets] * [Forms]![Frmbookflight]![Cost] 'This is working'

[Forms]![Frmbookflight]![Numberofseats] = [Forms]![Frmbookflight]![Numberofseats] - [numberoftickets] '**THIS IS STILL CAUSING ME PROBLEMS**'

End If
End Sub

Also any help on limiting the number of entries into a subform?
Thanks Ian


[This message has been edited by ian_ok (edited 04-22-2002).]
 
If you are referring to a field within the form that the module is based, try Me.[numberoftickets]. If you are referring to a field in a subform then you need to referrence the main form to:


Forms![MainForm]![Subform]![Numberofseats]

See if that makes any difference
 
I still get errors!
This is what each form/sub is called minus the []:

Main form called [Frmbookflight]
Numberofseats (field)

Subform 1 called [Passenger subform]
Numbeoftickets (field)

Ian
 
Try

[Forms]![Frmbookflight]![Numberofseats] = ([Forms]![Frmbookflight]![Numberofseats] - Me.[numberoftickets]) '**THIS IS STILL CAUSING ME PROBLEMS**'

If that doesn't work, try taking out the () and see if you have any luck
 
I'm still having a nightmare....

Private Sub numbeoftickets_AfterUpdate()
'Check if that number of tickets available'
If Forms![Frmbookflight]![Numberofseats] < Me.numbeoftickets Then
MsgBox "That number of tickets are not available"
'**Would also like to get a setfocus on numberofticets here, but can't get this to work**'
Exit Sub
Else
'Ticket calculation'
totalcost = [numbeoftickets] * [Forms]![Frmbookflight]![Cost] 'This is working'

'***************ERRORS****************'

'**Tried and doesn't work get meesage CAN'T FIND field numberoftickets**'
Forms![Frmbookflight]![Numberofseats] = [Forms]![Frmbookflight]![Numberofseats] - [Forms]![Frmbookflight]![Passenger subform]![numberoftickets]

'**This comes up with error CANT FIND FIELD Me either with or with out the brackets**'
[Forms]![Frmbookflight]![Numberofseats] = [Forms]![Frmbookflight]![Numberofseats] - [Forms]![Frmbookflight]![Passenger subform]!Me.numbeoftickets

'**This comes up with error CANT FIND FIELD Me either with or with out the brackets**'
[Forms]![Frmbookflight]![Numberofseats] = [Forms]![Frmbookflight]![Numberofseats] - Me.[numberoftickets]
End If
End Sub
 
Do you fancy sending me the bits I would need so I could fiddle with it a bit? It's difficult to visualise the problem but I'm happy to look at it if you want to send it on.
 

Users who are viewing this thread

Back
Top Bottom