Update Record from a form using a button

doobybug

New member
Local time
Today, 01:09
Joined
Jul 28, 2009
Messages
3
Hi,

I am very new to this so any help will be very much appreciated.

I have 2 tables:
Branches

BranchId (PK)
Name
Population
A
B
C

CityMarket

CityMarketId (PK)
BranchId (FK)
A
B
C

This is to get the relation that a branch can have various CityMarkets.

Now I have a form for Branches to input the data. In this form I have a button to view the City Markets of that particular branch. This would have the number of A, B, and C Outlets as well.

Thus I want to make it possible that if there is data in CityMarkets Form I would be able to get the totals of A, B and C outlets of that particular and update branches automatically with a press of a button.

Any help please?

This is what I have! It doesn't work however

Private Sub GetData_Click()
Dim strQRY As String
strQRY = " SELECT BranchId, Sum([A Outlets]) AS SumOfA, " & _
" Sum([B Outlets]), Sum([C & D Outlets]), Sum([Wholesale General]), " & _
" Sum([Wholesale Semi/Conf]), Sum(Catering), Sum([Table Top]), Sum(Others) " & _
" FROM CityMarket " & _
" WHERE BranchID = " & Me.Text86 & _
" GROUP BY BranchID"
Debug.Print strQRY
Dim strSQL As String
strSQL = " UPDATE Branches" & _
" SET [A Outlets] = strQRY.[SumOfA]" & _
" WHERE Branches.BranchID = [Forms]![RegBranch]![RegBranch1].[Form].[BranchId]"
Debug.Print strSQL
DoCmd.RunSQL strSQL
End Sub
 

Users who are viewing this thread

Back
Top Bottom