Most very small cameras have a limited flash range.

The flash on the ixus40 has a maximum range of 3.5 meters (11.5 feet), if you are not using optical zoom.

The flash on the ixus40 has a maximum range of 2 meters (6.6 feet) if you are using optical zoom.

The pictures you are getting with flash are probably normal for that camera.

...
..
.