WASHINGTON -- Following an election in which the National Rifle Association spent $23 million to keep Republicans in control of Congress, the House GOP voted for a second time to make it possible for those deemed mentally incompetent by the federal government to purchase weapons.

The House voted, 240-175, largely among party lines, to pass the Veterans 2nd Amendment Protection Act, which would require a judge to rule that veterans posed a danger to themselves or others before they could be denied the right to buy guns.

Just two House Republicans voted no. One of them was New Jersey's Rep. Leonard Lance (R-7th Dist.)

In voting no, Lance said the bill "could put veterans' safety at risk," and noted that the right of veterans to appeal such a designation was added to legislation enacted last year to speed up federal approval of new drugs.

Congressional Republicans last month voted to overturn the requirement that the Social Security Administration report to the gun database the names of those with mental illnesses who need representatives to handle their disability and supplemental benefit checks. President Donald Trump, whose campaign was backed by $30 million in NRA expenditures, signed the measure.

The latest measure would prevent the Department of Veterans Affairs from reporting the veterans it deemed mentally incompetent to the database used for background checks of gun purchasers.

The NRA argued that veterans were prohibited from buying guns simply because they needed assistance to handle their finances.

"The constitutional rights of our veterans must be strongly protected," said Chris W. Cox, the NRA's chief lobbyist. "Needing help managing your money does not make you a danger to society,"

The other four New Jersey Republicans voted yes and six of the state's seven House Democrats voted no. Rep. Donald Payne Jr. (D-10th Dist.) did not vote.

Lance also cited the opposition of the Veterans Coalition for Common Sense, which supports gun regulations and whose members include retired Gens. Wesley Clark, Michael V. Hayden and David Petraeus.

The group said the measure would remove the names of 174,000 veterans, some of whom suffer from dementia, schizophrenia and post traumatic stress disorder, from the background check database.

NRA spent $53 million on the 2016 elections, all of it to elect Republicans. Only five groups spent more, according to the Center for Responsive Politics, a Washington-based research group.

Separately, gun rights groups, including the NRA, contributed $5.9 million, with 98 percent of their money going to Republicans, according to the center.

Supporters of gun control donated $1.5 million, with 98 percent going to Democrats. A super political action committee funded by former New York City Mayor Michael Bloomberg spent $13.4 million to support candidates in both parties who support gun regulations, according to the center.

The other House Republican to vote no on the bill was Dan Donovan of New York.

Jonathan D. Salant may be reached at jsalant@njadvancemedia.com. Follow him on Twitter @JDSalant or on Facebook. Find NJ.com Politics on Facebook.